Delete Files Older Than x Days



The find utility on linux allows you to pass in a bunch of interesting arguments, including one to execute another command on each file. We’ll 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.
find /path/to/files* -mtime +5 -exec rm {} \;
Note that there are spaces between rm, {}, and \;

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.

Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

4 comments:

GST Training said...

What you're saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I'm sure you'll reach so many people with what you've got to say.

Buy Contact Lenses said...

I really appreciate your professional approach. These are pieces of very useful information that will be of great use for me in future.

Tangki Fiber said...

Definitely believe that which you said. Your favorite reason appeared to be on the web the easiest thing to be aware of. I say to you, I definitely get irked while people think about worries that they just do not know about. You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people could take a signal. Will likely be back to get more. Thanks
Tangki Panel

2 player games said...

This is truly a decent and instructive, containing all data furthermore greatly affects the new innovation

Post a Comment

Popular Posts