Posts Tagged ‘remove files’

Linux – remove files older than 7 days

June 2, 2011 1 comment

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

I find this particularly useful when I want to clear down trace files that have been building up over time. To do this I would move to the oracle bdump directory, then execute the following command line code:

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

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

Code breakdown

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

Further reading

It is possible to execute different commands upon found files, however this is outside the scope of this post. For more information on the find command please see the find man pages: Find Man Page