Pages

Saturday, April 16, 2016

Linux – Remove files Older Than 7 Days

Linux – Remove files Older Than 7 Days

The Linux find command has several different uses. One of these uses is to remove files that are older than x amount of days.

This particularly useful when we want to clear down trace files that have been building up over time. To do this execute the following command line code:

Go to trace file directory and execute the below command

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

The above code will remove all trace files in the current directory that are older than 7 days.

Example:

find <filename> -mtime +<number of days> -exec <command> \;

Find <filename> – finds the files specified by the filename
-mtime +<number of days> – days older than current system date
-exec <command> – command to execute with found files

No comments:

Post a Comment