1

I have a folder with thousands of subfolders named numerically (from 1 to 200000)

I would like to delete all the folders (and files inside of them) which are named 100000+

Is there a way to do this from a linux command line?

2 Answers 2

1

There are several ways to do this, but the simplest is probably:

rm -r [1-2][0-9][0-9][0-9][0-9][0-9]

I would advise you to put an echo in front of the rm first, just to make sure that it is finding the directories you really want to remove.

It is possible you may run out of memory for the command line, in which case you may need to use:

for f in [1-2][0-9][0-9][0-9][0-9][0-9]; do rm -r $f; done
2
  • How do I modify the first example to do it automatically? it seems to be asking me whether to remove it for every file
    – emkay
    Sep 14, 2014 at 20:50
  • Use rm -rf to stop the prompts.
    – AFH
    Sep 14, 2014 at 20:59
3

Yes, assuming a POSIX shell, use shell pattern matching:

rm -rf *???????

in that directory. Note that this matches any file or subdirectory with 7 or more characters, so be careful!

You must log in to answer this question.

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