1

The folder structure is as below

A/B/C1/
A/B/C2/
X/B/C1/
X/B/C2/

I want to delete all C2 folders however keep C1 intact.

What is the correct command for that?

2 Answers 2

1

This works just fine: rm -rf */*/C2/ Please be careful, because it says nothing when deleteing all the files and folders recersively. If you want to be cautious, you can use: rm -ri */*/C1/ instead which prompts for every deletion.

2
  • You are right. Thanks! But the correct one is rm -rf */*/C2/ because I want to delete C2
    – mahmood
    Jul 8, 2015 at 13:39
  • Yes, I fixed that. Sorry for the typo.
    – Ho1
    Jul 8, 2015 at 13:41
0

I think the safest method would be like this:

find . -maxdepth 3 -name C2 -type d -exec rm -fr '{}' ';'
1
  • You should also provide a -mindepth of 3.
    – Ho1
    Jul 8, 2015 at 20:05

You must log in to answer this question.

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