unixdirectoryrm

How to delete only directories and leave files untouched


I have hundreds of directories and files in one directory.

What is the best way deleting only directories (no matter if the directories have anything in it or not, just delete them all)

Currently I use ls -1 -d */, and record them in a file, and do sed, and then run it. It rather long way. I'm looking for better way deleting only directories


Solution

  • In one line:

    rm -R `ls -1 -d */`
    

    (backquotes)