File Cleanup Question

This is more of a general Linux question and forgive my ignorance on the matter.

Is there a command to delete the files within a directory and its sub directories while leaving the directory structure intact?

You can use find . -type f -exec rm {} +.

I.e., find, starting from the current directory, all files, and then execute the rm command on those files.

Be careful, and make sure you don’t delete anything important that you can’t restore :wink:

1 Like

Print the files first to check:

find . -type f

If you’re sure you want to delete every file listed, add -delete:

find . -type f -delete

tree is useful to view the structure. It should also tell you there are 0 files in the last line.

tree