I need to delete all files older than 5 days in all subfolders, but not the folders themselves. I know the command:
find /path/to/files* -mtime +5 -exec rm {} \;
But how can I tell Ubuntu to check in all subfolders, yet never delete the folders themselves. Will I need a -maxdepth 5 somewhere?
Thanks.
Best Answer
First of all, don't give a glob to
find
(nofiles*
), just give it the parent directory (/path/to/
). It will deal with recursing into it and finding all files. Next,rm
will never delete directories, so you don't need to worry about that either. Still, the simplest way is:Note the
-type f
which tellsfind
to only look at files and the-delete
which, well, deletes them. This is more efficient than calling a separaterm
for each result.