How can I recursively delete old files and prune resulting empty directories?

if you define "older than" by having a modification time of more than 60 days, the following command will delete your old files:

find /your/dir -mtime +60 -exec rm -f {} \;

for pruning empty directories you could use this command:

find /your/dir -type d -exec rmdir {} \;

it doesn't exactly find empty directories, but since rmdir does not delete directories containing files, it will only delete the empty ones.


I think you can combine these two commands into one:

find /your/dir -type f -mtime +60 -delete -or -type d -empty -delete

Note: -delete implies -depth.