Home > Commands, Linux > 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.

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

Advertisements
  1. September 20, 2014 at 9:35 PM

    I love what you guys tend to be up too. This sort of
    clever work and coverage! Keep up the superb works guys I’ve added you
    guys to my blogroll.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: