Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

Thanks!

share|improve this question

3 Answers 3

This should work:

vi `ls | head -1`

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

share|improve this answer

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.

share|improve this answer

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.

/home/Username/Pictures/icons/
├── 96audio.png
├── 96media.png
├── 96mpeg.png
├── acidrip.png
├── advancedSettings.png
├── airfoilSpeakers.png
├── alchemy.png
├── many many more images..

share|improve this answer

Your Answer

 
discard

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.