2

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?

3 Answers 3

6

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
4
  • 1
    main- is not consistent. It's name depends on the name of actual main.x
    – zengr
    Mar 13, 2011 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, 2011 at 6:05
  • I will give it a shot and update the question. Thanks
    – zengr
    Mar 13, 2011 at 6:07
  • Do not use the -r if you dont need it. Mar 13, 2011 at 15:04
2

Simple command:

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

Good luck!

1
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.

You must log in to answer this question.

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