Wednesday 11 November 2009

Unix - Delete files older than 7 days

We are using IBM AIX servers. We wanted to delete the log files older than 7 days to reclaim the space.

First i need to find the files older than 7 days and then remove them.

$find . -mtime +7 -exec rm -f {} \;

Here i have used find command to find the files in current directory("." means current directory) alternatively you can specify a directory path like "/opt/oracle/admin/log"

And used the parameter -mtime to specify the number of days where i have given +7.

If you specify 7 then seven or more days old files are selected
If you specify +7 then 8 or more days old files are selected.

Then execute the rm command with the -exec option.

No comments: