Posts Tagged ‘find’

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


Linux – Find Command

November 25, 2010 1 comment

The find command is used to find files and directories on a linux/unix system. It will search any set of directories that you specify for files/directories matching a given search criteria. You can search by name, owner, group, type, permission, date, and other criteria. Search is recursive and will search the specified directory and its subdirectories providing the user has permission to view the contents of that directory.

Find all files in current directory and it’s sub-directories

Find followed by a . will search for all files in the current directory and it’s sub-directories and print the output.

dgoh-data-01:oracle@OASLIVE1 > find .

Find all sub-directories within the current directory by given owner

If you want to find all sub-directories of the current directory with the owner ‘Oracle’ then you would execute the following command:

$  find . -type d -user oracle -ls

Categories: Commands, Linux Tags: , ,