Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
92 views

Delete Files Procedure On Linux

The document provides instructions for using the find command in Linux to delete files older than a specified number of days. The find command searches for files modified more than 5 days ago (using -mtime +5) and then uses -exec rm {} \; to execute the rm command on each file found, deleting files older than 5 days. The command finds files matching the wildcard path, dates them, and removes them in one line to clear out old unnecessary files.

Uploaded by

Biswajit Das
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Delete Files Procedure On Linux

The document provides instructions for using the find command in Linux to delete files older than a specified number of days. The find command searches for files modified more than 5 days ago (using -mtime +5) and then uses -exec rm {} \; to execute the rm command on each file found, deleting files older than 5 days. The command finds files matching the wildcard path, dates them, and removes them in one line to clear out old unnecessary files.

Uploaded by

Biswajit Das
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Delete Files Older Than x Days on Linux

The find utility on linux allows you to pass in a bunch of interesting arguments, including one
to execute another command on each file. Well use this in order to figure out what files are
older than a certain number of days, and then use the rm command to delete them.
Command Syntax
find /path/to/files* -mtime +5 -exec rm {} \;
Note that there are spaces between rm, {}, and \;
Explanation

The first argument is the path to the files. This can be a path, a directory, or a
wildcard as in the example above. I would recommend using the full path, and make
sure that you run the command without the exec rm to make sure you are getting the
right results.

The second argument, -mtime, is used to specify the number of days old that the file
is. If you enter +5, it will find files older than 5 days.

The third argument, -exec, allows you to pass in a command such as rm. The {} \; at
the end is required to end the command.

This should work on Ubuntu, Suse, Redhat, or pretty much any version of linux.

You might also like