>_ IzzyLab

Hands-on task

This task is step 7 of the course “Running a server”

Auto-cleanup of temporary files

medium~7 min

The /tmp/uploads directory keeps filling up with abandoned files — both old and fresh ones are already there. Set up a cron job (in root's crontab) that every 10 minutes deletes files older than 60 minutes from it (use find with -mmin). Fresh files must not be touched.

What you'll practise:
  • cron
  • crontab
  • find
  • -mmin
  • task scheduler

Topic breakdown

cron is the system scheduler: each crontab line is five schedule fields (minute hour day month day_of_week) plus a command. A period of "every N units" is set with the step syntax */N in the corresponding field; the other fields with an asterisk mean "any value". To select files by age, find has predicates in minutes and in days — with a small threshold it's important to use the minute one, not the day one. You edit your own job list via crontab -e and view it via crontab -l.

What's checked

  1. a job for /tmp/uploads runs every 10 minutes
  2. the command deletes files older than an hour
  3. files younger than an hour stay

What it looks like