Quantcast
Channel: Web Host
Viewing all articles
Browse latest Browse all 31

How to Find and Delete Files in Directory Based on Modification Date

$
0
0

How to find and delete files in a Linux directory based on when the file had been modified from a certain amount of days ago - this can be useful for dealing with directories with copious amounts of files like email boxes and log folders.

 

First to see the files modified or created based on a certain date:

find /path-to-directory -mtime +5 -exec ls -l {} \;

This will list all the files created or modified 5 days prior to the current date.

 

Then to remove the files

find /path-to-directory -mtime +5 -exec rm -f {} \;

This will remove all those files previously listed.

 

Alter the '-mtime' argument in the command to change the amount of days, by adjusting the figure after it. '+5' will preserve any files created/modified withiin the last 5 days and delete files modified older then 5 days ago.

Tags:


Viewing all articles
Browse latest Browse all 31

Trending Articles