Monday, October 15, 2007

Cron-job to delete unused thumbnails

I found that the hidden folder .Thumbnails (under /home/adder1972/) can grow very large after e.g. looking through a few years of pictures in my Pictures-folder. In Gnome (Nautilus) you can view hidden files and folders by pressing Ctrl + H. Here is a tip on how to delete unused thumbnails automatically.

Cron-job is a tool for running repetitive tasks in Linux. I made a cron-job for deleting the content of .Thumbnails if the file hasn't been accessed for a while. It provides a nice balance between conserving drive space and having thumbnails quickly available for the system.

I made a plain text document in the /etc/cron.d folder. I called the file "thumb", but that doesn't really matter. The file contains just one line:

0 21 * * * root find /home/*/.thumbnails/ -type f -atime +6 -exec rm '{}' \;

The format for the cron-commands are explained in detail in "man cron" and the find-commands in "man find".

The command tells the Linux-box to find all the thumbnail-files in all the home-folders (if you have several users) and delete the ones that has not been accessed during that last 7 days (today +6 days). The command is performed as root.

As long as the Linux-box is up and running at 9PM (21h), the cron-job is running.

No comments: