Question

I am working on the Linux shell, and I usually have to deal with files that have complicated names. For example, I list the files of the current directory using ls:

MOD11A1.A2012193.h12v03.005.2012196013543.hdf
MOD11A1.A2012193.h12v04.005.2012196013541.hdf
MOD11A1.A2012193.h12v05.005.2012196013541.hdf

And then, if I need to open one of them, I would write:

vim MOD11A1.A2012193.h12v03.005.2012196013543.hdf

The way I do it, is by first selecting the file name from the list provided by ls, right click, copy it, right click, paste it after vim. Is there a shorter way to do this?

Was it helpful?

Solution

Use wildcard expansion, i.e. for the second file:

vim *v04*41*

or, if your shell supports it, tab-completion:

type vim M; press [Tab], that completes all up to next difference, i.e. OD11A1.A2012193.h12v0; type 4; press [Tab], and so on.

OTHER TIPS

If you would like open first of hdf files then use:

vim `ls -1 *.hdf | head -n 1`

ls-1 - minifies dump to just a name per row

head -n 1 - selects first item only

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