How to remove only the content of directories?

Try:

find /var/myfolder -type f -delete

This gets all the regular files under /var/myfolder and deletes them leaving only the directories.


With zsh, use the . glob qualifier to match only regular files:

rm -- **/*(.)

This deletes all the (non-hidden) regular files in the current directory and its subdirectories recursively. Add the D glob qualifier to delete hidden regular files (and regular files in hidden directories) as well.


You can run rm */* in /var/myfolder

Tags:

Shell

Files