Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to remove all directories from the pwd but leave the files in the pwd alone. If the content of my pwd is:


then I'd like to be left with just


I assume that I need to use rm -r -i

Am I correct?

share|improve this question
up vote 3 down vote accepted

No that would give you "missing operand" since you didn't specify anything. Putting a "*" would prompt also for files.

I'd give a try to:

find -mindepth 1 -maxdepth 1 -type d -exec rm -r {} \;

The "mindepth 1" will exclude "." from the results, the "maxdepth 1" will exclude trying to do under the directories that will anyway get deleted (therefore creating a warning). But in practice you could leave them both out if you agree to have a few "innocent" warnings.

share|improve this answer

I found this one somewhere:

rm -r */

Seems the easiest way to go. With your example, you would have to confirm each case, if you have 5 files it's OK, but with bigger file structures an interactive mode is't the way to go... Just as a suggestion, if it's important information, make a backup...

share|improve this answer
That will also follow symbolic links, which very probably isn't desired here. – JdeBP Feb 7 '14 at 16:43

Something like this should work:

find /path -type d -exec rm -rf '{}' \;

-type d looks for only directories

share|improve this answer


rm -rf ./*/

That avoids interactive mode an deletes only directories in your local directory.

share|improve this answer

You must log in to answer this question.

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