Find using wildcard

I have a situation where I have a group of directories like this:


Each one of these 4 directories contains files. What I am trying to do is create a script which copies all of the files out of foo_01, foo_02 and foo_03 into the foo directory, then deletes the source directories so that I’m always just left with the foo directory only. This needs to happen in a loop because there will be an unknown number directories to copy.

I think what needs to happen is to first identify all directories which contain the character string “foo_”, and I’m thinking that could be done using a wildcard, but I’m having trouble figuring out exactly how to do this. Any thoughts/suggestions??

Thanks in advance for any assistance.

do you DIR command to search for


since foo will never match foo_* you should be in good shape.

Alternatively if you know all directories (that you are looking for) are in the format of foo_XX where XX is a 2 digit number, you could make the search even more confined by using

foo_?? which will only match anything that is foo_ followed by 2 characters. To limit it to numbers only you need to start looking at regular expressions, which may be more efficient if you expand it.

Sponsor our Newsletter | Privacy Policy | Terms of Service