2

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?

1
  • 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. Commented Sep 8, 2012 at 0:09

1 Answer 1

2

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]*
2
  • now if i wanted to move those files would i just use that same command replace ls to mv
    – brian fox
    Commented Sep 7, 2012 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
    Commented Sep 8, 2012 at 0:18

You must log in to answer this question.

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