DEV Community

Ahmad Ya'kob Ubaidullah
Ahmad Ya'kob Ubaidullah

Posted on

How to automatically delete file after 7 days

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

Top comments (0)