Ubuntu – the command to remove all files but not directories

command linedeletefilesrm

Let's say I have a directory tree like this:

FOLDER:
    file1
    file2
    file3
    Subfolder1:
        file1
        file2
    Subfolder2:
        file1
        file2

If I used rm -r FOLDER/*, everything in FOLDER would be deleted including sub-directories. How can I delete all files in FOLDER and in its sub-directories without deleting actual directories?

Best Answer

What you're trying to do is recursive deletion. For that you need a recursive tool, such as find.

find FOLDER -type f -delete