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 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?

share|improve this question
add comment

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
share|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. –  matthias krull Mar 13 '11 at 15:04
add comment
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.

share|improve this answer
add comment

Simple command:

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

Good luck!

share|improve this answer
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.