Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know how to open directory, but I do not know how to select a file from the command line.


I do not know how it works, but when I move any file to a directory and then open the directory that this file is selected.

share|improve this question
Do you mean so a nautilus window opens, with a specific file highlighted and the status bar reading something like '"file.txt" selected (2.6 MB)'? – Richard Holloway Aug 31 '10 at 17:00
Or do you mean you wish to open a file from the command line? – Richard Holloway Aug 31 '10 at 17:00
"Do you mean so a nautilus window opens, with a specific file highlighted [...]" Yes, exactly what I mean – lukasz Aug 31 '10 at 17:35
And what do you want this for ??? – Black Block Nov 25 '11 at 18:39
up vote 4 down vote accepted

I think it's actually easier than it seems. What I tried is just this:

nautilus <path_to_file>

At first, the file doesn't look to be selected, but that's just because the nautilus window isn't active. If you click on it, you'll see that the file name is selected.

Since I guess you want to have that extra visual feedback, I used xdotool to make a simple test to select /var/log/dpkg.log as follows:

nautilus /var/log/dpkg.log && sleep 3 && xdotool search -name log windowactivate

What you should see is that nautilus in opened with using /var/log/ directory and that after three seconds the window is activated (the window name is just log) and the file name is highlighted since it's selected.

Note: in this example if sleep is set to a shorter time you might not get the expected result since you need the window to be properly displayed before trying to activate it.

share|improve this answer

I don't think there's an option to do this. See:

You can open a file as if you had double clicked it in nautilus using the xdg-open command:

xdg-open file

If you really wanted to have this specific feature, it would require hacking on the Nautilus code.

share|improve this answer
+1 For the information on the xdg-open command. I can confirm that there is no way to open nautilus with a specific file selected. – Richard Holloway Aug 31 '10 at 17:02

When you in an xterm, navigating directories on the command line, and then want to pop up a nautilus window for that directory, do this:

nautilus --browser .
share|improve this answer

The gnome-open command will open a directory with the appropriate application, which in this case is Nautilus:

gnome-open PATH

This will open the directory /tmp using the Nautilus file browser:

gnome-open /tmp


cd /tmp
gnome-open .

I like the gnome-open command because you can use this exact same command to open a file with the appropriate application. No need to remember any funny flags. It just works.

gnome-open file.pdf will open the PDF in a PDF browser. gnome-open will open a zip file using the Zip archive viewer.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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