Pages

Search This Blog

Tuesday, February 11, 2020

Delete Files Older Than X Days in Unix

In this example X is replaced with 7.

List all files older than X days:

find /path/to/files/ -type f -mtime -7 -exec ls -l {} \; 

Delete all files older than X days:

find /path/to/files/ -type f -mtime -7 -exec rm -f {} \;

Move all files with extension '.arc' older than X days:
find /path/to/files/ -type f -name '*.arc' -mtime +7 -exec mv {} /path/to/archive/ \;
 
 

No comments:

Post a Comment