Question

Suppose I'm at a terminal in Linux/UNIX and I run ls and see the following displayed:

my_file_1.txt my_file_2.txt

Now I want to open the first one in gedit, or maybe it's a folder and I want to enter it.

Is running gedit my_file_1.txt the fastest way to do this? Suppose the file has a long and awkward name, is there any shortcut along the lines of gedit ls[0] - where I'm asking gedit to open the first item in the list returned?

If there's not, I won't lose any sleep over it, but if such a shortcut exists I'd make use of it, especially when dealing with lengthy file and folder names.

Was it helpful?

Solution

You could do this:

gedit "$(ls | head -1)"

But probably using filename completion or cutting and pasting with the mouse will be easier.

OTHER TIPS

I haven't seen anything that indexes the results of ls.

What you could do is the auto-completion feature that is built in. For example if your file name is very long you can just start writing a little bit of the file name and hit 'Tab' until you find the file you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top