I have the following folder structure:

parent
 - folder1
   - main1.x
   - main1.y
   - main1.z
   - main1-626262.x
   - main1-626263.x
   - main1-626264.x
   - main1-626265.x
   - main1-626266.x
   - main1-626267.x
 - folder2
   - main2.x
   - main2.y
   - main2.z
   - main2-726262.x
   - main2-726263.x
   - main2-726264.x
   - main2-726265.x
   - main2-726266.x
   - main2-726267.x

Now, I want to remove: main-*********.x

So, my required folder structure:

parent
 - folder1
   - main1.x
   - main1.y
   - main1.z
 - folder2
   - main2.x
   - main2.y
   - main2.z

So, how can I achieve this?

link|improve this question

feedback

3 Answers

up vote 4 down vote accepted

Try this:

find * -name 'main?-*.x' | xargs echo rm -rf

The above prints a command that removes the unwanted directories (without actually removing them). If it looks OK, simply run the printed command, or run

find * -name 'main?-*.x' | xargs rm -rf
link|improve this answer
1  
main- is not consistent. It's name depends on the name of actual main.x – zengr Mar 13 '11 at 6:02
Then please modify the -name option to suit your needs. You can use the wildcards such as ? and *. You can even use grep in between find and xargs to filter the directories to be removed. – netvope Mar 13 '11 at 6:05
I will give it a shot and update the question. Thanks – zengr Mar 13 '11 at 6:07
Do not use the -r if you dont need it. – mugen kenichi Mar 13 '11 at 15:04
feedback
rm */*[0-9][0-9][0-9][0-9][0-9][0-9].*

But needs a bash or sh to evaluate. Don't know about C-Shell, if it doesn't work some similar syntax will be available.

link|improve this answer
feedback

Simple command:

rm `find ./ -name 'main?-*.x'` -rf

Good luck!

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.