Thursday, July 31, 2008

How To Delete Linux Files Older Than 360 days

Searching files recursively for deletion can be real exchausting specially if the target files are queried by their file age. Recursive searching in all linux distribution can be done by using linux find command as find linux command makes recursive searches real easy.

Find command is so powerful that it can actually boosts file management operations specially on recursive file operations.

Here's how to delete files that are older than 365 days from your linux file system.

Find all MP3 files from /home/user folder and delete them if they are more than 360 days old

# find /home/user  -name '*.mp3' -mtime +360 -exec rm {} \;


The above command specifies

/home/user   as the target folder location

*.mp3  as the exact target files to delete, remember linux is case-sensitive

-mtime as find parameter to check for file age

360 as the file age triggerpoint to delete any found file

-exec as a linux command concatenation to execute the next command while doing the first linux command

rm as the linux file delete command

{} \; as the loopback parameter to repeat the search and file deletion back again

To avoid any interaction when deleting files, simply change

rm {}

to

rm -rf {}

Be careful of using this find and delete command, as it does file deletion recursively. This command can be used to clean up old files from FTP and Samba file servers using linux job scheduling.

All is done.

Related Post:

HowTo: Delete All Thumbs.db Recursively

HowTo: Find And Count JPG Files Recursively

Delete Zero-sized Filename Recursively

Find Hidden Linux File Recursively

Move Linux Files Recursively

Rename Linux File Recursively

Delete Files and Folders Recursively

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy