Suppose I'm browsing a directory from command line with lots of files with long names. Is there a easy/fast way to open the first file from the directory, or simply any of these files? In my case they are pictures, so if I'm able to open one of them, I can browse the pictures from the application (eog, for instance). Completion doesn't help in this case, as the pictures are named with a similar prefix and the suffix is a date -- so completing one filen name ends up taking some time. I know, it's just some seconds.. but the idea of using command line is to be fast, right?


4 Answers 4


This should work:

vi `ls | head -1`

Opens vi with the first file (or folder) in the current working directory as parameter.


You can use the gnome-open or xdg-open command, to open any file/folder from within terminal. Like in the tree view below, the first image is named 96audio.png, which is located in /home/Username/Pictures/icons/.

Now you can use this command, to open it, and then use your default image-viewer, to browse the rest of images within this dir:

gnome-open /home/Username/Pictures/icons/96audio.png

When it comes to long file names, you can use the Tab-key (), to auto-complete file names. So for 96audio.png type in `96a, followed by -key.

├── 96audio.png
├── 96media.png
├── 96mpeg.png
├── acidrip.png
├── advancedSettings.png
├── airfoilSpeakers.png
├── alchemy.png
├── many many more images..


slightly modified from this which will open all files matching the regex in the quotes, in this case, files with the name with any series of characters, ending in '.jpg'. The -exec <command> {} + basically takes the output of find, and calls the <command> on each of them, as long as there is at least one file found

find . -name '*.jpg' -exec viewnior {} +

If you have lots of files in a single directory ending in .jpg obviously this would be very unwieldy as it would open all of them, but you can also narrow down which file names you want to open by using the regex.

find . -name '*common_string*.jpg' -exec viewnior {} +

You would then need to change .jpg to whatever your file extension is, and viewnior to whatever image viewing/editing program you use.


In addition to this answer: If you are using VIM, try to open the current folder in VIM's file browser with the following command:

$ vim .

At the top you'll find instructions on how to change the order of the listed files.

Just hit ENTER on the file you would like to open. (You can get back to the file browser by closing VIM with :E instead of :q)

Hope this helps someone.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .