How to remove file older than 3 days

You might ask how to remove file that existed for 3 days or more.

It is quite straight forward and easy from Unix(Linux) command if you using find.

You may refer to the sample script as below.
find . -type f -mtime +3 -exec rm -rf {} \;

As the command above, it will find the file type of file and file existed for 3 days, execute the command of rm (remove). To be clear you may refer to the detail as below.
type – file type, you may define f for file and d for directory
mtime – It could be define that the last modified date and +3 is 3 days
exec – execution of your Linux command
\; – indicate that your command end

Alternatively,  you may use atime which last active time to replace mtime. Have fun.

Published by

Mick Genie

Mick Genie is the founder of and working at ExaBytes Network Sdn Bhd and WPWebHost web host company. He is expertise in Windows and Linux environment especially web hosting related information, tips and trick as well as the IT Information.