DEV Community

loading...

How to automatically delete file after 7 days

abigoroth profile image Ahmad Ya'kob Ubaidullah ・1 min read

below is the command to delete file which is created more than 7 days ago.

find /home/system/backup/gitn_sdn_berhad/* -mtime +7 -type f -delete
Enter fullscreen mode Exit fullscreen mode

then we put it inside crontab like below:

0 0 * * * find /home/system/backup/gitn_sdn_berhad/* -mtime +7 -type f -delete
Enter fullscreen mode Exit fullscreen mode

your should only store latest 7 days of files after this cron is running.

ref: https://askubuntu.com/a/789637/591250

Discussion (0)

pic
Editor guide