I have two related questions, both probably (but not necessarily preferentially) accepting the same answer :

  1. When browsing or exploring the filesystem in a GUI, I want to be able to right click on the empty space between the files, choose a menu item and say 'open terminal in this folder,' optionally as root
  2. Do the converse when using the terminal, optionally as root

I use Universe with kubuntu but have Debian Lenny running with gnome installed separately, so anything on kde or gnome would work


Terminal to Nautilus

For the terminal side of things, I would just add this to my ~/.bashrc:

alias browse="xdg-open ."
alias browse-root="gksudo xdg-open ."

Nautilus to Terminal

The nautilus-open-terminal extension that others have mentioned is great for most use, but it does not provide a way to open a root shell. The easiest way for you to get this functionality is to save a script like the following as ~/.gnome2/nautilus-scripts/Open in Terminal (Root):


gnome-terminal -x sudo -s

A fun variation on this would be to make a GNOME Terminal profile called "root" with a scary red background color, an initial title of "Root Terminal", and the custom shell command sudo -s. You'd then use a Nautilus script like this:


gnome-terminal --window-with-profile=root
  • xdg-open . and sudo xdg-open . are be better because they work on KDE as well as GNOME. – dv3500ea Sep 29 '10 at 16:56
  • 1
    That's usually the better way to go, but currently sudo xdg-open . fails due to this bug. – ændrük Sep 29 '10 at 20:09

You can use xdg-open to open files and directories from the command line. I have an alias of xopen to make the typing a little easier. Put this in your ~/.bashrc to do that, and to have a root file browser using sudo:

alias xopen="xdg-open"
alias xopen-root="sudo xdg-open"

It will open the file in the application that would be used if you double-clicked on it. For example, if you named a text file, it would open in gedit. And if you pass it a directory, it will open the file browser. So if I am in my home directory I can do

$ xopen Documents
$ xopen .

and the file browser (nautilus for me) will open that directory. Also note that xdg-open will return immediately - the new program is launched as it's own process and you can type in your next command.

To open a terminal from the nautilus file browser, you should install the nautilus-open-terminal package. Then you can right click on a folder, or in the blank space below the files, and open a terminal with the path set to that directory. Not sure how to make it a root terminal though - I always just use sudo myself.

  • You should consider adding to your answer then aendruk tip on xopen-sudo. – Javier Rivera Sep 29 '10 at 16:58

There's a nautilus script handily packaged in the Ubuntu repositories to do this for you. Click here to install or run the following command.

sudo apt-get install nautilus-open-terminal

You may have to restart gnome/nautilus for it to work.


If you already have Ubuntu-tweak installed, you can also just tick the box for nautilus extensions.

Not sure if it's compatible with Lenny, right enough! :-)

alt text

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.