Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm starting to pick up Linux. I have one directory called class03 with five directories in it:

_html
html
dothtml
images
123

I need a one-line command that lists all files with -01, -02 and -03 in the file name in those directories.

I can get all the files to list with the command:

ls _html/ html/ dothtml/ images/

When i try to put the restrictions it still lists without the restriction and errors with the *-0[123]

I tried:

ls *-0[123] * _html/ html/ dothtml/ images/

and:

ls _html/ html/ dothtml/ images/ * -0[123] *

So what do I need to do to make the code work in one command?

share|improve this question
    
By the way, if you want to list all the files in, say, the _html and html directories, it's good enough to say ls _htlm html -- you don't need to type / at the end of each directory name. –  Scott Sep 8 '12 at 0:09
add comment

1 Answer

If there are no other directories, you can use just

ls */*-0[123]*

If there are more directories you want to exclude, you can use the brace expansion:

ls {{,_,dot}html,images,123}/*-0[123]*
share|improve this answer
    
now if i wanted to move those files would i just use that same command replace ls to mv –  brian fox Sep 7 '12 at 23:53
    
@brianfox: Sure. But be careful if files with the same name exist in different source directories, you will get mv: will not overwrite just-created. –  choroba Sep 8 '12 at 0:18
add comment

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.