To remove files from the /tmp directory every hour using a cron job, you can create a new crontab entry using the following steps:

1.       Open the crontab editor by running the following command:

                     crontab -e

2.      Add a new line to the crontab file with the following format:

0 * * * * find /tmp -type f -mmin +60 -delete

This will run the find command every hour at the start of the hour (i.e., when the minute is 0). The find command will delete all files in the /tmp directory that are older than 60 minutes (i.e., have not been accessed in the last hour).

3.      Save and close the crontab file.

The find command in the above crontab entry finds all files in the /tmp directory (/tmp -type f) that were last modified over 60 minutes ago (-mmin +60), and deletes them (-delete).

Note that this cron job will only remove files from the /tmp directory that are older than 60 minutes. If you need to remove files that are newer than that or have specific patterns, you can adjust the find command accordingly.

Previous Post Next Post