gedit
is a graphical editor. All graphical applications need an environment variable called $DISPLAY
.
If you have running graphical session start gedit
like this:
user@host:~# DISPLAY=:0 gedit config/database.yml
In case you dont have access to a graphical session try
user@host:~# nano config/database.yml
As far as sudo gedit
, nothing dire, just poor practice, especially as of late. How much harder would it be to suggest sudo -H gedit
?
-H
, --set-home
Request that the security policy set the HOME environment variable to the home directory specified by the target user's password database entry. Depending on the policy, this may be the default behavior.
What does happen?
You get a couple of root owned files in your home folder. One (recently-used.xbel
) will likely return to user ownership. This can happen when a file is deleted and re-created. To see what sudo gedit
has changed, run find ~ -user root -group root
and see what is returned. By default, this is should be nothing.
With that command, you may see a couple files owned by root. One would be a new .file
, .gvfs
, and sooner or later a root-owned ~/.cache/dconf
and the aforementioned recently-used.xbel
.
So no 'the sky is failing' stuff, but still. Now there have been reports that continued use causes other issues but not going to claim what I don't see here.
Also note that as of 13.10 a sudo gedit
will use the user's gedit config rather than root's gedit config. Again just bad practice so why continue to do so or suggest others do so?
Best Answer
You are entering the
sudo gedit /path/to/file
command into a shell (by default bash), but modern shells use the '!' character for special purposes. Special characters can be interpreted without special meaning by preceding them with the '\' character.Try:
instead of
In modern shells the commands you enter are remembered and you can reenter them by using the '!' character.
!!
for example reenters the last command. As Uri points out, this is called an event designator. The bash interpreter also let's you use Ctrl+R to easily find commands you want to reenter, but the '!' mechanism is still there for us old-timers who have the habit of using '!' instead. Other uses of "!" include the $! parameter, and its use in arithmetic and logical expressions.A bash reference may be helpful if you run into such mysteries because shells can be very complicated. The gnu bash manual is here.
Uri helpfully mentioned that you should use gksu or gksudo rather than sudo. There is an explanation here: What is the difference between "gksudo nautilus" and "sudo nautilus"?.