remove files older than X days

find example to remove files older than 5 days:

find /path/to/files* -mtime +5 -type f -exec rm {} \;

Note that this command will not work when it finds too many files. It will yield an error like:

bash: /usr/bin/find: Argument list too long

Use this:

find /path/to/files* -mtime +5 -type f | xargs rm

This entry was posted in CentOS, Linux and tagged , , , . Bookmark the permalink.

Leave a Reply