How to properly edit system files (as root) in GUI (and CLI) in Linux?Cannot open GUI editors in superuser modeNano through Sudoedit = No colorsWhat is your favourite shell script GUI/CLI editor and why?How to create and edit a text file from the bash shellEdit/Remove CLI System NoticeHow do I remotely edit files via ssh?linux + visudo + how to remove sub folder and sub filesEncrypt root file system linuxCan a Unix (Linux) System Launch a GUI from CLI Like (Apple/Microsoft) DOS?What are the GNU programs that I need with Linux if I only edit files?How to edit files in text editor and not terminal when using nano command?CLI (NO GUI) linux distro small memory old pc

LED on same Pin as Toggle Switch, not illuminating

"which" command doesn't work / path of Safari?

What is the white spray-pattern residue inside these Falcon Heavy nozzles?

How can I fix this gap between bookcases I made?

Patience, young "Padovan"

How to type dʒ symbol (IPA) on Mac?

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?

I probably found a bug with the sudo apt install function

How does one intimidate enemies without having the capacity for violence?

Why can't I see bouncing of a switch on an oscilloscope?

Non-Jewish family in an Orthodox Jewish Wedding

Circuitry of TV splitters

How do you conduct xenoanthropology after first contact?

Simulate Bitwise Cyclic Tag

How to report a triplet of septets in NMR tabulation?

Is there a minimum number of transactions in a block?

How is this relation reflexive?

If Manufacturer spice model and Datasheet give different values which should I use?

Why are 150k or 200k jobs considered good when there are 300k+ births a month?

Can I make popcorn with any corn?

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

Japan - Plan around max visa duration

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?



How to properly edit system files (as root) in GUI (and CLI) in Linux?


Cannot open GUI editors in superuser modeNano through Sudoedit = No colorsWhat is your favourite shell script GUI/CLI editor and why?How to create and edit a text file from the bash shellEdit/Remove CLI System NoticeHow do I remotely edit files via ssh?linux + visudo + how to remove sub folder and sub filesEncrypt root file system linuxCan a Unix (Linux) System Launch a GUI from CLI Like (Apple/Microsoft) DOS?What are the GNU programs that I need with Linux if I only edit files?How to edit files in text editor and not terminal when using nano command?CLI (NO GUI) linux distro small memory old pc






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1

















System: Linux Mint 18.1 64-bit Cinnamon.




Objective: To define Bash aliases to launch various CLI and GUI text editors while opening a file in root mode from gnome-terminal emulator.




Progress



For example, the following aliases seem to work as expected:



For CLI, in this example I used Nano (official website):



alias sunano='sudo nano'


For GUI, in this example I used Xed (Wikipedia article):



alias suxed='sudo xed'


They both open a file as root.




Problem



I have an issue with gksudo in conjunction with sublime-text:



alias susubl='gksudo /opt/sublime_text/sublime_text'


Sometimes it works. It just does not do anything most of the time.



How do I debug such a thing with inconsistent behavior? It does not output anything. No error message or similar.




Question



gksudo has been deprecated in Debian and also no longer included in Ubuntu 18.04 Bionic, so let me re-formulate this question to a still valid one:



How to properly edit system files (as root) in GUI (and CLI) in Linux?



Properly in this context I define as safely in case, for instance, a power loss occurs during the file edit, another example could be lost SSH connection, etc.










share|improve this question






























    -1

















    System: Linux Mint 18.1 64-bit Cinnamon.




    Objective: To define Bash aliases to launch various CLI and GUI text editors while opening a file in root mode from gnome-terminal emulator.




    Progress



    For example, the following aliases seem to work as expected:



    For CLI, in this example I used Nano (official website):



    alias sunano='sudo nano'


    For GUI, in this example I used Xed (Wikipedia article):



    alias suxed='sudo xed'


    They both open a file as root.




    Problem



    I have an issue with gksudo in conjunction with sublime-text:



    alias susubl='gksudo /opt/sublime_text/sublime_text'


    Sometimes it works. It just does not do anything most of the time.



    How do I debug such a thing with inconsistent behavior? It does not output anything. No error message or similar.




    Question



    gksudo has been deprecated in Debian and also no longer included in Ubuntu 18.04 Bionic, so let me re-formulate this question to a still valid one:



    How to properly edit system files (as root) in GUI (and CLI) in Linux?



    Properly in this context I define as safely in case, for instance, a power loss occurs during the file edit, another example could be lost SSH connection, etc.










    share|improve this question


























      -1












      -1








      -1


      1








      System: Linux Mint 18.1 64-bit Cinnamon.




      Objective: To define Bash aliases to launch various CLI and GUI text editors while opening a file in root mode from gnome-terminal emulator.




      Progress



      For example, the following aliases seem to work as expected:



      For CLI, in this example I used Nano (official website):



      alias sunano='sudo nano'


      For GUI, in this example I used Xed (Wikipedia article):



      alias suxed='sudo xed'


      They both open a file as root.




      Problem



      I have an issue with gksudo in conjunction with sublime-text:



      alias susubl='gksudo /opt/sublime_text/sublime_text'


      Sometimes it works. It just does not do anything most of the time.



      How do I debug such a thing with inconsistent behavior? It does not output anything. No error message or similar.




      Question



      gksudo has been deprecated in Debian and also no longer included in Ubuntu 18.04 Bionic, so let me re-formulate this question to a still valid one:



      How to properly edit system files (as root) in GUI (and CLI) in Linux?



      Properly in this context I define as safely in case, for instance, a power loss occurs during the file edit, another example could be lost SSH connection, etc.










      share|improve this question


















      System: Linux Mint 18.1 64-bit Cinnamon.




      Objective: To define Bash aliases to launch various CLI and GUI text editors while opening a file in root mode from gnome-terminal emulator.




      Progress



      For example, the following aliases seem to work as expected:



      For CLI, in this example I used Nano (official website):



      alias sunano='sudo nano'


      For GUI, in this example I used Xed (Wikipedia article):



      alias suxed='sudo xed'


      They both open a file as root.




      Problem



      I have an issue with gksudo in conjunction with sublime-text:



      alias susubl='gksudo /opt/sublime_text/sublime_text'


      Sometimes it works. It just does not do anything most of the time.



      How do I debug such a thing with inconsistent behavior? It does not output anything. No error message or similar.




      Question



      gksudo has been deprecated in Debian and also no longer included in Ubuntu 18.04 Bionic, so let me re-formulate this question to a still valid one:



      How to properly edit system files (as root) in GUI (and CLI) in Linux?



      Properly in this context I define as safely in case, for instance, a power loss occurs during the file edit, another example could be lost SSH connection, etc.







      linux editors sudoedit






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 19 hours ago







      Vlastimil

















      asked Apr 5 '17 at 12:22









      VlastimilVlastimil

      8,5111566146




      8,5111566146




















          3 Answers
          3






          active

          oldest

          votes


















          5
















          You shouldn’t run an editor as root unless absolutely necessary, you should set sudoedit up appropriately. Then you can do



          SUDO_EDITOR="/opt/sublime_text/sublime_text -w" sudoedit yourfile


          sudoedit will check you’re allowed to do this, make a copy of the file that you can edit with changing ids, start your editor, and then, when the editor exits, copy the file back if it has been changed.



          I’d suggest a function rather than an alias:



          function susubl 
          export SUDO_EDITOR="/opt/sublime_text/sublime_text -w"
          sudoedit "$@"



          although as Jeff Schaller pointed out, you can use env to put this in an alias and avoid changing your shell’s environment:



          alias susubl='env SUDO_EDITOR="/opt/sublime_text/sublime_text -w" sudoedit'


          The -w option ensures that the Sublime Text invocation waits until the files are closed before returning and letting sudoedit copy the files back.






          share|improve this answer
































            1
















            Expanding on Stephen Kitt's answer




            1. Find out, on what path your editor is located, e.g.:



              $ which nano
              /usr/local/bin/nano


              As you can see, I use compiled nano, not the packaged version; no matter this can change from system/config to other system/config.




            2. The CLI text editors like vi or nano do not seem to have the wait option, so for my nano and vi one can write functions like this:



              # CLI
              sunano() env SUDO_EDITOR='/usr/local/bin/nano' sudoedit "$@";
              suvi() env SUDO_EDITOR='/usr/bin/vi' sudoedit "$@";



            3. The GUI text editors, on the contrary, like Linux Mint's integrated xed, free programs like Visual Studio Code (code), or paid programs like Sublime Text (subl) all seem to have the wait option, and you need to use it in order to avoid the problem described in my question, you can use something similar to these functions:



              # GUI
              susubl() env SUDO_EDITOR='/opt/sublime_text/sublime_text -w' sudoedit "$@";
              sucode() env SUDO_EDITOR='/usr/share/code/bin/code -w' sudoedit "$@";
              suxed() env SUDO_EDITOR='/usr/bin/xed -w' sudoedit "$@";



            What the -w (--wait) option effectively does is, that the editor will wait on the terminal until you close it, thus waiting on close of the editor, enabling further actions to be planned and done on an editor close, in this instance to save the sudoedit changes. Normally, it would just free the terminal, and you would get a new prompt.



            Imagine another useful usage for this:



            code -w /home/vlastimil/.bash_aliases; . /home/vlastimil/.bash_aliases


            Hopefully, with this example, I make myself clearer.




            Generalized and POSIX-ly written ready-to-use function



            You should, of course, compile your own list of favorited editors, these are my own, take it only as an example, and populate the list with yours.



            # Text editing as root; The proper way through `sudoedit`.
            sudoedit_internal()


            printf '%sn' "sudoedit_internal(): The path to '$1' editor does not exist on this system." 1>&2
            return

            editor_wait_option=$2
            shift 2
            env SUDO_EDITOR="$editor_path $editor_wait_option" sudoedit "$@"

            # CLI
            suvi() sudoedit_internal vi '' "$@";
            sunano() sudoedit_internal nano '' "$@";
            # GUI
            sucode() sudoedit_internal code -w "$@";
            susubl() sudoedit_internal subl -w "$@";
            suxed() sudoedit_internal xed -w "$@";
            sugedit() sudoedit_internal gedit -w "$@";





            share|improve this answer
































              0














              Different solution: I never edit system files directly, I make a copy somewhere(*), edit the copy (with my usual editor), and sudo cp when done.



              (*) I have a directory for this, where all files are kept in one place:



              • naturally keeps a list of all the file that I have changed

              • easy to version

              • easy to backup

              • easy to transfer to another machine





              share|improve this answer























                Your Answer








                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "106"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: false,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );













                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f356113%2fhow-to-properly-edit-system-files-as-root-in-gui-and-cli-in-linux%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                5
















                You shouldn’t run an editor as root unless absolutely necessary, you should set sudoedit up appropriately. Then you can do



                SUDO_EDITOR="/opt/sublime_text/sublime_text -w" sudoedit yourfile


                sudoedit will check you’re allowed to do this, make a copy of the file that you can edit with changing ids, start your editor, and then, when the editor exits, copy the file back if it has been changed.



                I’d suggest a function rather than an alias:



                function susubl 
                export SUDO_EDITOR="/opt/sublime_text/sublime_text -w"
                sudoedit "$@"



                although as Jeff Schaller pointed out, you can use env to put this in an alias and avoid changing your shell’s environment:



                alias susubl='env SUDO_EDITOR="/opt/sublime_text/sublime_text -w" sudoedit'


                The -w option ensures that the Sublime Text invocation waits until the files are closed before returning and letting sudoedit copy the files back.






                share|improve this answer





























                  5
















                  You shouldn’t run an editor as root unless absolutely necessary, you should set sudoedit up appropriately. Then you can do



                  SUDO_EDITOR="/opt/sublime_text/sublime_text -w" sudoedit yourfile


                  sudoedit will check you’re allowed to do this, make a copy of the file that you can edit with changing ids, start your editor, and then, when the editor exits, copy the file back if it has been changed.



                  I’d suggest a function rather than an alias:



                  function susubl 
                  export SUDO_EDITOR="/opt/sublime_text/sublime_text -w"
                  sudoedit "$@"



                  although as Jeff Schaller pointed out, you can use env to put this in an alias and avoid changing your shell’s environment:



                  alias susubl='env SUDO_EDITOR="/opt/sublime_text/sublime_text -w" sudoedit'


                  The -w option ensures that the Sublime Text invocation waits until the files are closed before returning and letting sudoedit copy the files back.






                  share|improve this answer



























                    5












                    5








                    5









                    You shouldn’t run an editor as root unless absolutely necessary, you should set sudoedit up appropriately. Then you can do



                    SUDO_EDITOR="/opt/sublime_text/sublime_text -w" sudoedit yourfile


                    sudoedit will check you’re allowed to do this, make a copy of the file that you can edit with changing ids, start your editor, and then, when the editor exits, copy the file back if it has been changed.



                    I’d suggest a function rather than an alias:



                    function susubl 
                    export SUDO_EDITOR="/opt/sublime_text/sublime_text -w"
                    sudoedit "$@"



                    although as Jeff Schaller pointed out, you can use env to put this in an alias and avoid changing your shell’s environment:



                    alias susubl='env SUDO_EDITOR="/opt/sublime_text/sublime_text -w" sudoedit'


                    The -w option ensures that the Sublime Text invocation waits until the files are closed before returning and letting sudoedit copy the files back.






                    share|improve this answer

















                    You shouldn’t run an editor as root unless absolutely necessary, you should set sudoedit up appropriately. Then you can do



                    SUDO_EDITOR="/opt/sublime_text/sublime_text -w" sudoedit yourfile


                    sudoedit will check you’re allowed to do this, make a copy of the file that you can edit with changing ids, start your editor, and then, when the editor exits, copy the file back if it has been changed.



                    I’d suggest a function rather than an alias:



                    function susubl 
                    export SUDO_EDITOR="/opt/sublime_text/sublime_text -w"
                    sudoedit "$@"



                    although as Jeff Schaller pointed out, you can use env to put this in an alias and avoid changing your shell’s environment:



                    alias susubl='env SUDO_EDITOR="/opt/sublime_text/sublime_text -w" sudoedit'


                    The -w option ensures that the Sublime Text invocation waits until the files are closed before returning and letting sudoedit copy the files back.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 22 hours ago

























                    answered Apr 5 '17 at 12:46









                    Stephen KittStephen Kitt

                    180k25409488




                    180k25409488























                        1
















                        Expanding on Stephen Kitt's answer




                        1. Find out, on what path your editor is located, e.g.:



                          $ which nano
                          /usr/local/bin/nano


                          As you can see, I use compiled nano, not the packaged version; no matter this can change from system/config to other system/config.




                        2. The CLI text editors like vi or nano do not seem to have the wait option, so for my nano and vi one can write functions like this:



                          # CLI
                          sunano() env SUDO_EDITOR='/usr/local/bin/nano' sudoedit "$@";
                          suvi() env SUDO_EDITOR='/usr/bin/vi' sudoedit "$@";



                        3. The GUI text editors, on the contrary, like Linux Mint's integrated xed, free programs like Visual Studio Code (code), or paid programs like Sublime Text (subl) all seem to have the wait option, and you need to use it in order to avoid the problem described in my question, you can use something similar to these functions:



                          # GUI
                          susubl() env SUDO_EDITOR='/opt/sublime_text/sublime_text -w' sudoedit "$@";
                          sucode() env SUDO_EDITOR='/usr/share/code/bin/code -w' sudoedit "$@";
                          suxed() env SUDO_EDITOR='/usr/bin/xed -w' sudoedit "$@";



                        What the -w (--wait) option effectively does is, that the editor will wait on the terminal until you close it, thus waiting on close of the editor, enabling further actions to be planned and done on an editor close, in this instance to save the sudoedit changes. Normally, it would just free the terminal, and you would get a new prompt.



                        Imagine another useful usage for this:



                        code -w /home/vlastimil/.bash_aliases; . /home/vlastimil/.bash_aliases


                        Hopefully, with this example, I make myself clearer.




                        Generalized and POSIX-ly written ready-to-use function



                        You should, of course, compile your own list of favorited editors, these are my own, take it only as an example, and populate the list with yours.



                        # Text editing as root; The proper way through `sudoedit`.
                        sudoedit_internal()


                        printf '%sn' "sudoedit_internal(): The path to '$1' editor does not exist on this system." 1>&2
                        return

                        editor_wait_option=$2
                        shift 2
                        env SUDO_EDITOR="$editor_path $editor_wait_option" sudoedit "$@"

                        # CLI
                        suvi() sudoedit_internal vi '' "$@";
                        sunano() sudoedit_internal nano '' "$@";
                        # GUI
                        sucode() sudoedit_internal code -w "$@";
                        susubl() sudoedit_internal subl -w "$@";
                        suxed() sudoedit_internal xed -w "$@";
                        sugedit() sudoedit_internal gedit -w "$@";





                        share|improve this answer





























                          1
















                          Expanding on Stephen Kitt's answer




                          1. Find out, on what path your editor is located, e.g.:



                            $ which nano
                            /usr/local/bin/nano


                            As you can see, I use compiled nano, not the packaged version; no matter this can change from system/config to other system/config.




                          2. The CLI text editors like vi or nano do not seem to have the wait option, so for my nano and vi one can write functions like this:



                            # CLI
                            sunano() env SUDO_EDITOR='/usr/local/bin/nano' sudoedit "$@";
                            suvi() env SUDO_EDITOR='/usr/bin/vi' sudoedit "$@";



                          3. The GUI text editors, on the contrary, like Linux Mint's integrated xed, free programs like Visual Studio Code (code), or paid programs like Sublime Text (subl) all seem to have the wait option, and you need to use it in order to avoid the problem described in my question, you can use something similar to these functions:



                            # GUI
                            susubl() env SUDO_EDITOR='/opt/sublime_text/sublime_text -w' sudoedit "$@";
                            sucode() env SUDO_EDITOR='/usr/share/code/bin/code -w' sudoedit "$@";
                            suxed() env SUDO_EDITOR='/usr/bin/xed -w' sudoedit "$@";



                          What the -w (--wait) option effectively does is, that the editor will wait on the terminal until you close it, thus waiting on close of the editor, enabling further actions to be planned and done on an editor close, in this instance to save the sudoedit changes. Normally, it would just free the terminal, and you would get a new prompt.



                          Imagine another useful usage for this:



                          code -w /home/vlastimil/.bash_aliases; . /home/vlastimil/.bash_aliases


                          Hopefully, with this example, I make myself clearer.




                          Generalized and POSIX-ly written ready-to-use function



                          You should, of course, compile your own list of favorited editors, these are my own, take it only as an example, and populate the list with yours.



                          # Text editing as root; The proper way through `sudoedit`.
                          sudoedit_internal()


                          printf '%sn' "sudoedit_internal(): The path to '$1' editor does not exist on this system." 1>&2
                          return

                          editor_wait_option=$2
                          shift 2
                          env SUDO_EDITOR="$editor_path $editor_wait_option" sudoedit "$@"

                          # CLI
                          suvi() sudoedit_internal vi '' "$@";
                          sunano() sudoedit_internal nano '' "$@";
                          # GUI
                          sucode() sudoedit_internal code -w "$@";
                          susubl() sudoedit_internal subl -w "$@";
                          suxed() sudoedit_internal xed -w "$@";
                          sugedit() sudoedit_internal gedit -w "$@";





                          share|improve this answer



























                            1












                            1








                            1









                            Expanding on Stephen Kitt's answer




                            1. Find out, on what path your editor is located, e.g.:



                              $ which nano
                              /usr/local/bin/nano


                              As you can see, I use compiled nano, not the packaged version; no matter this can change from system/config to other system/config.




                            2. The CLI text editors like vi or nano do not seem to have the wait option, so for my nano and vi one can write functions like this:



                              # CLI
                              sunano() env SUDO_EDITOR='/usr/local/bin/nano' sudoedit "$@";
                              suvi() env SUDO_EDITOR='/usr/bin/vi' sudoedit "$@";



                            3. The GUI text editors, on the contrary, like Linux Mint's integrated xed, free programs like Visual Studio Code (code), or paid programs like Sublime Text (subl) all seem to have the wait option, and you need to use it in order to avoid the problem described in my question, you can use something similar to these functions:



                              # GUI
                              susubl() env SUDO_EDITOR='/opt/sublime_text/sublime_text -w' sudoedit "$@";
                              sucode() env SUDO_EDITOR='/usr/share/code/bin/code -w' sudoedit "$@";
                              suxed() env SUDO_EDITOR='/usr/bin/xed -w' sudoedit "$@";



                            What the -w (--wait) option effectively does is, that the editor will wait on the terminal until you close it, thus waiting on close of the editor, enabling further actions to be planned and done on an editor close, in this instance to save the sudoedit changes. Normally, it would just free the terminal, and you would get a new prompt.



                            Imagine another useful usage for this:



                            code -w /home/vlastimil/.bash_aliases; . /home/vlastimil/.bash_aliases


                            Hopefully, with this example, I make myself clearer.




                            Generalized and POSIX-ly written ready-to-use function



                            You should, of course, compile your own list of favorited editors, these are my own, take it only as an example, and populate the list with yours.



                            # Text editing as root; The proper way through `sudoedit`.
                            sudoedit_internal()


                            printf '%sn' "sudoedit_internal(): The path to '$1' editor does not exist on this system." 1>&2
                            return

                            editor_wait_option=$2
                            shift 2
                            env SUDO_EDITOR="$editor_path $editor_wait_option" sudoedit "$@"

                            # CLI
                            suvi() sudoedit_internal vi '' "$@";
                            sunano() sudoedit_internal nano '' "$@";
                            # GUI
                            sucode() sudoedit_internal code -w "$@";
                            susubl() sudoedit_internal subl -w "$@";
                            suxed() sudoedit_internal xed -w "$@";
                            sugedit() sudoedit_internal gedit -w "$@";





                            share|improve this answer

















                            Expanding on Stephen Kitt's answer




                            1. Find out, on what path your editor is located, e.g.:



                              $ which nano
                              /usr/local/bin/nano


                              As you can see, I use compiled nano, not the packaged version; no matter this can change from system/config to other system/config.




                            2. The CLI text editors like vi or nano do not seem to have the wait option, so for my nano and vi one can write functions like this:



                              # CLI
                              sunano() env SUDO_EDITOR='/usr/local/bin/nano' sudoedit "$@";
                              suvi() env SUDO_EDITOR='/usr/bin/vi' sudoedit "$@";



                            3. The GUI text editors, on the contrary, like Linux Mint's integrated xed, free programs like Visual Studio Code (code), or paid programs like Sublime Text (subl) all seem to have the wait option, and you need to use it in order to avoid the problem described in my question, you can use something similar to these functions:



                              # GUI
                              susubl() env SUDO_EDITOR='/opt/sublime_text/sublime_text -w' sudoedit "$@";
                              sucode() env SUDO_EDITOR='/usr/share/code/bin/code -w' sudoedit "$@";
                              suxed() env SUDO_EDITOR='/usr/bin/xed -w' sudoedit "$@";



                            What the -w (--wait) option effectively does is, that the editor will wait on the terminal until you close it, thus waiting on close of the editor, enabling further actions to be planned and done on an editor close, in this instance to save the sudoedit changes. Normally, it would just free the terminal, and you would get a new prompt.



                            Imagine another useful usage for this:



                            code -w /home/vlastimil/.bash_aliases; . /home/vlastimil/.bash_aliases


                            Hopefully, with this example, I make myself clearer.




                            Generalized and POSIX-ly written ready-to-use function



                            You should, of course, compile your own list of favorited editors, these are my own, take it only as an example, and populate the list with yours.



                            # Text editing as root; The proper way through `sudoedit`.
                            sudoedit_internal()


                            printf '%sn' "sudoedit_internal(): The path to '$1' editor does not exist on this system." 1>&2
                            return

                            editor_wait_option=$2
                            shift 2
                            env SUDO_EDITOR="$editor_path $editor_wait_option" sudoedit "$@"

                            # CLI
                            suvi() sudoedit_internal vi '' "$@";
                            sunano() sudoedit_internal nano '' "$@";
                            # GUI
                            sucode() sudoedit_internal code -w "$@";
                            susubl() sudoedit_internal subl -w "$@";
                            suxed() sudoedit_internal xed -w "$@";
                            sugedit() sudoedit_internal gedit -w "$@";






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 15 hours ago

























                            answered Oct 7 '18 at 12:16









                            VlastimilVlastimil

                            8,5111566146




                            8,5111566146





















                                0














                                Different solution: I never edit system files directly, I make a copy somewhere(*), edit the copy (with my usual editor), and sudo cp when done.



                                (*) I have a directory for this, where all files are kept in one place:



                                • naturally keeps a list of all the file that I have changed

                                • easy to version

                                • easy to backup

                                • easy to transfer to another machine





                                share|improve this answer



























                                  0














                                  Different solution: I never edit system files directly, I make a copy somewhere(*), edit the copy (with my usual editor), and sudo cp when done.



                                  (*) I have a directory for this, where all files are kept in one place:



                                  • naturally keeps a list of all the file that I have changed

                                  • easy to version

                                  • easy to backup

                                  • easy to transfer to another machine





                                  share|improve this answer

























                                    0












                                    0








                                    0







                                    Different solution: I never edit system files directly, I make a copy somewhere(*), edit the copy (with my usual editor), and sudo cp when done.



                                    (*) I have a directory for this, where all files are kept in one place:



                                    • naturally keeps a list of all the file that I have changed

                                    • easy to version

                                    • easy to backup

                                    • easy to transfer to another machine





                                    share|improve this answer













                                    Different solution: I never edit system files directly, I make a copy somewhere(*), edit the copy (with my usual editor), and sudo cp when done.



                                    (*) I have a directory for this, where all files are kept in one place:



                                    • naturally keeps a list of all the file that I have changed

                                    • easy to version

                                    • easy to backup

                                    • easy to transfer to another machine






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 19 hours ago









                                    xenoidxenoid

                                    3,2491826




                                    3,2491826



























                                        draft saved

                                        draft discarded
















































                                        Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f356113%2fhow-to-properly-edit-system-files-as-root-in-gui-and-cli-in-linux%23new-answer', 'question_page');

                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

                                        Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

                                        Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.