Thursday, January 27, 2011

Removing Files Older than a Certain Number of Days

Using the find command, we can remove files that have not been modified in a certain number of days old using the mtime option:
  -mtime n
File's data was last modified n*24 hours ago. See the comments for -atime
to understand how rounding affects the inter‐pretation of file modification times.
To delete files that are older than 6 months, we can use:
  $ find . -type f -mtime +180 | xargs rm
Or alternatively:
  $ find . -type f -mtime +180 -exec rm {} \;

No comments:

Post a Comment