Say I have a folder open in Nautilus that's in my /home/user/temp directory. I'd like to move a folder from there to my /opt directory (it's a program). Is there a way I can elevate the copy command up to a sudo so that I can copy the folder without having to start a new instance of Nautilus from the command line?


As far as I can say, based on what I know and have experienced:

sudo is used for command line applications/commands and gksudo is useful when you try to run a program using the Run Application dialog window by pressing Alt+F2.

I have read that gksudo is just the graphic version of sudo.

Anyway, you can both drop sudo nautilus and/or gksu nautilus in a terminal for the purpose to do what you wish, having the same effect both commands. But if you want to omit the terminal and you wish to run it directly with the "Run Application" dialog window, just press Alt+F2 and write gksu nautilus, after which you will be prompted to enter your password, then the nautilus file browser will open with root privileges.

Additionally, you can achieve to open files/folders as root with a single click by using the "Open as Administrator" option via right click. Which in any case will open a new nautilus instance for the given folder and will open files as root, this may also open/run applications as root but I haven't tested it yet.

enter image description here

You can get the "Open as Administration" option in your contextual menu by installing nautilus-gksu via command line: sudo apt-get install nautilus-gksu or by using synaptic as shown in the next image:

enter image description here

Good luck!

  • It looks like I have to add something to get the "Open as" command. Do you recall what it was? I'm in Ub 11.
    – jcollum
    Jan 25 '12 at 18:53
  • nautilus-gksu, via synaptic (image added) or command line (also provided in the answer) Jan 25 '12 at 19:13
  • 3
    Here is why we should use gksu nautilus not sudo: askubuntu.com/q/11760
    – Takkat
    Jan 25 '12 at 20:03
  • 2
    Did nautilus-gksu move? Disappear? I can't find it in USC or apt-get.
    – jcollum
    Apr 25 '13 at 20:40
  • 2
    @jcollum nautilus-gksu no longer exists in the repository as of Ubuntu 12.04.
    – IQAndreas
    Jul 15 '13 at 2:08

you need to run Nautilus as root

type this in the terminal

gksu nautilus

now you can move using the GUI.

or use this command

sudo mv -r /home/user/temp/<foldername>/ /opt/
  • 1
    So the answer is "You can't without restarting Nautilus"?
    – jcollum
    Jan 25 '12 at 18:30
  • you don't need to restart nautilus, just open another instance with the gksu command. But if you mean "open nautilus with my user and then got root privileges in that instance to move files" maybe that's what you need upubuntu.com/2011/12/…
    – zurdo
    Jan 25 '12 at 18:46
  • You will need to open a new nautilus window, but to make things easier you copy the location from the bar, and run the command: gksu nautilus "/path/to/dir/pasted/here" (the quotes around the path are important)
    – IQAndreas
    Jul 15 '13 at 2:07

Here's the nautilus-script I use to open an admin (root) Nautilus window:

# This Nautilus script opens the current nautilus window in admin mode.
# Requires: perl, liburi-perl

ERROR_NEED_PERL="This script requires the liburi-perl package. Install it and try again."
GKSUDO_MESSAGE="Enter your password to open an admin window on: "
ERROR_BROKEN_LINK="Broken link."

## Check for liburi-perl (and hence perl)
let PERLOK=$(dpkg-query -W --showformat='${Status}\n' liburi-perl|grep "install ok installed")
if [ "" == "$PERLOK" ]; then
   zenity --error --text "$ERROR_NEED_PERL"
   exit 1

[ $LEN_NSSFP -lt 0 ] && let LEN_NSSFP=0
[ $LEN_NSSU -lt 0 ] && let LEN_NSSU=0

## if clicking happens on the Desktop (or a file or folder on it),
## $1 will be a path (i.e. with "/" in it); otherwise (in a folder
## window) $1 will be just a file or folder name (without path).
## Note that selecting the home desktop namespace extension yields
## a $# of zero but NAUTILUS_SCRIPT_SELECTED_FILE_PATHS pointing to the
## target (in the computer (computer:///) and trash (trash:///) desktop
## namespace extension cases, ...PATHS is empty).

## Initially, we stripped the file:// prefix from NAUTILUS...CURRENT_URI,
## yielding the full path, and then retrofit spaces, like this:
#OBJECT="`echo -n $NAUTILUS_SCRIPT_CURRENT_URI | cut -d'/' -f3- | sed 's/%20/ /g'`"
## However, this fails if any special characters other than spaces are in the path,
## such as accented letters, etc. We need to convert not just spaces, but any
## UTF-8 embedded in there...The URI<->path conversion requires perl (and liburi-perl):
OBJECT=$( echo "$NAUTILUS_SCRIPT_CURRENT_URI" | perl -MURI -le 'print URI->new(<>)->dir' )
## ->file is to be used for file URIs instead of ->dir, which is for directory URIs

## Add the selection to the path, if defined and unique
if [ $# -eq 1 ] ; then
   ## If a single Desktop object, override
   if echo $1 | grep -q "/" ; then ## Desktop (or object on desktop)
   else ## $1 is a simple file or folder name, without a path
      ## The container could be root (/)
# elif [ $# -eq 0 -a -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ] ; then
elif [ $# -eq 0 ] ; then
   ## desktop name space extension selected?
   if [ -n "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" ] ; then ## Home
   elif [ -n "$NAUTILUS_SCRIPT_SELECTED_URIS" ] ; then ## Computer, Trash
      ## These typically map to root (/)
#     OBJECT="`echo ${NAUTILUS_SCRIPT_SELECTED_URIS:0:LEN_NSSU} | cut -d'/' -f3- | sed 's/%20/ /g'`"
      OBJECT=$( echo "$OBJECT" | perl -MURI -le 'print URI->new(<>)->dir' )
## Note that a desktop shortcut (.desktop file) does not trip -h
if [ -h "$OBJECT" ] ; then ## symbolic link
   ## readlink has no "follow symlinks as far as they exist" option
   OBJECT=`readlink -e "$OBJECT"`
   if [ -z "$OBJECT" ] ; then
      zenity --error --text "$ERROR_BROKEN_LINK"
      exit 1

# zenity --info --text "\$OBJECT is « $OBJECT »"
if [ -f "$OBJECT" ] ; then
   ## Regular file
   DIR=`dirname "$OBJECT"`
   ## Directory (or no object)

## If DIR is empty, gnome-open opens in the default (home) directory (i.e. "~") anyway
#if [ -z "$DIR" ] ; then
#   DIR=~

## At this point, the test [ ! "$CONTEXT" = "$DIR" ] serves to indicate
## that the target directory is not matched to the one the script was
## invoked from (if any).

gksudo --message "$GKSUDO_MESSAGE$DIR" gnome-open "$DIR"

exit $?

Another dandy solution is to launch another copy of Nautilus with root (sudo) privileges from a command line:

gksudo xdg-open <path> &

The closing & means the command runs as a background job; hence the use of gksudo (using sudo would mean an invisible prompt that you can't respond to). xdg-open takes care of launching an explorer window (nautilus or other).

You may need to install the xdg-utils and gksu packages beforehand.

You may get a bunch of warnings and Gtk-CRITICAL and Glib-GObject-CRITICAL messages upon closing the elevated Nautilus window, but these are harmless as far as I can tell. I'd love to get rid of them, if anyone knows how.

sudo mv /home/user/temp/[Filename] /opt

Instead of [Filename], type the name of your file without brackets [].

  • 2
    -1, doesn't address question... I didn't ask how to use the mv command.
    – jcollum
    Jan 25 '12 at 18:31
  • 3
    Using only one command as root is known as a better practice than opening graphical Nautilus as root.
    – Agmenor
    Jan 25 '12 at 18:50

Another easy way is

sudo gnome-open foldername

Or I would recommend installing nemo file manager. It has 'open as root' in its right click context menu

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.