Opening current directory from a terminal onto a file browser?

xdg-open .

xdg-open is part of the xdg-utils package, which is commonly installed by default in many distributions (including Ubuntu). It is designed to work for multiple desktop environments, calling the default handler for the file type in your desktop environment.

You can pass a directory, file, or URL, and it will open the proper program for that parameter. For example, on my KDE system:

  • xdg-open . opens the current directory in the Dolphin file manager
  • xdg-open foo.txt opens foo.txt in emacsclient, which I've configured to be the default handler for .txt files
  • xdg-open http://www.google.com/ opens google.com in my default web browser

The application opens as a separate window, and you'll get a prompt back in your terminal and can issue other commands or close your terminal without affecting your new GUI window.

I usually get a bunch of error message printed to stderr, but I just ignore them.

Edit:
Adding the arguments xdg-open . >/dev/null 2>&1 redirects the errors and the output. This call won't block your terminal. Binding this to an alias like filemanager='xdg-open . >/dev/null 2>&1' can come in handy.


Almost any GUI application (on X window systems) can be opened from a terminal window within that GUI. To open any GUI app, type the name of the executable at the shell prompt. Most file browsers take a directory as a command line argument, so you should usually pass . as the parameter.

Here are some examples for some popular systems, most X based systems work similarly.

On Gnome, you can run nautilus (the default file browser) directly, or on Gnome 2, you can use gnome-open to open any file (including directories) with the configured Gnome file handler application:

$ nautilus .

or

$ gnome-open .

On KDE, there are two popular file browsers, I'm not aware of a command similar to gnome-open, though gnome-open can be executed within KDE, but by default it opens Gnome apps.

$ dolphin .

or

$ konquerer .

On OS X, as mentioned in comments, a similar command line program, open can be used.

$ open .

What if you don't know the executable name of your system's file browser?

If on Gnome 2, use gnome-open . If on OS X, call open .. Each of these will execute the configured file browser for your GUI environment.

If you don't know of such a command in your window system, here's one way to find out on systems with a ps command that understands the options -u USER and -o FORMAT:

  1. In your terminal window, type ps -u$USER -o comm > /tmp/$$A
  2. In your GUI, start the file browser.
  3. Back in your terminal window, type ps -u $USER -o comm > /tmp/$$B (Notice the B suffix, this is a different file than step 1).
  4. Also in the terminal, type diff /tmp/$$[AB].

Should display the name of your file browser. It's possible you could see more than one name, if another program happened to start under your user id during the time between the calls to ps.

For example:

$ ps -u $USER -o comm > /tmp/$$A
$ # open file browser in gui
$ ps -u $USER -o comm > /tmp/$$B
$ diff /tmp/$$[AB]
95a96
> nautilus

Ubuntu uses as default file browser nautilus as far as I remember. Therefore to open a certain folder from terminal you can type something like the following:

nautilus /path/to/your/dir

or

cd /path/to/your/dir && nautilus .

nautilus automatically deataches itself from the terminal it was called, but suppose you are using another file browser, and you want to close the terminal from which you called your file browser, you can use nohup to do so. If you are using, let's say, thunar (another file browser), you can type the following:

nohup thunar /path/to/your/dir & exit