Wednesday, January 1, 2014

Remove files older than 7 days - Linux

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 we can access 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 -mtime + -exec \;
Find – finds the files specified by the filename
-mtime + – days older than current system date
-exec – 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

0 Comments: