1

I am using Ubuntu (the latest release).

In Ubuntu, I type gedit filename and after saving the file, I type sudo gedit filename (it gave me a warning), but what surprise me is that, it didn't show me the original file, and give me a "new file"(also named "filename") which is empty. so I get confused, and I try to type gedit filename(without sudo) again, and the original file shows again. It seems that these "two" files are stored in different place, since I can edit non-sudo file and sudo-file respectively.

The operating above are based on the command-line, and if I open the file via GUI approach, Ubuntu will show me the file which I didn't type sudo

But in the case of macOS (macOS 10.13), the sudo command is only used to improve permissions, and of course I cannot get "two" different files.

So, can anyone help me on this issue, why using sudo command to edit files can lead to such a situation? And does that mean these two files belong to two different users(in Ubuntu situation)?

  • Are you doing this at the same location? Do pwd in both terminals first. And please don't post images of text. Or at least make them minimum size. – Tomasz Jun 16 '18 at 12:43
  • 1
    It looks like sudo on the two systems are configured differently. The Ubuntu configuration is obviously resetting the HOME environment variable to home of the target user (root). – Kusalananda Jun 16 '18 at 12:59
  • Run pwd; sudo pwd on both systems and compare. – nohillside Jun 16 '18 at 13:00
  • @Tomaz yes, and i access to both two "files" to edit and save, as if they are stored in two different places! – Albert Zhang Jun 17 '18 at 12:26
1

You're doing it wrong in Ubuntu by using sudo gedit. You shouldn't use sudo to open graphical applications as root because this is a known cause of file corruption. That's why you get a warning like this in Ubuntu when you run sudo gedit filename .

** (gedit:14140): WARNING **: 16:10:13.541: Set document metadata failed:  
Setting attribute metadata::gedit-position not supported

Nautilus Admin (nautilus-admin) is a simple Python extension for the Nautilus file manager that adds some administrative actions to the right-click menu:

  • Open as Administrator: opens a folder in a new Nautilus window running with administrator (root) privileges.
  • Edit as Administrator: opens a file in a Gedit window running with administrator (root) privileges.

To install Nautilus Admin in all currently supported versions of Ubuntu open the terminal and type:

sudo apt install nautilus-admin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.