Clean Up Old Thumbnails February 15, 2006
Posted by Carthik in administration, commands, maintenance, snippets, ubuntu.trackback
The nautilus file manager shows you thumbnails of images, pdf files etc when you are browsing your directories. But you already know that. Nautilus also saves a copy of the thumbnails for later, to speed things up. The thumbnails are stored in your ~/.thumbnails directory. Over time, thumbnails keep accumulating, since, even if you delete a file (an image, say), the thumbnail remains. Cleaning this up might save you some space. It saved me about 650MB!
I found this neat command that you can execute to find and delete thumbnails that have not been accessed in the last 7 days. Deleting a thumbnail should not affect anything much, since if Nautilus cannot find a thumbnail, it will just create one anew.
$find ~/.thumbnails -type f -atime +7 -exec rm {} \;
You can put that code in your cron if you like, to have it run every month or so.
Fjern gamle ikoner
Man kan si mye pent om filviseren Nautilus, men neppe at den er gjerrig med plassbruken. I den skjulte mappen…
I disabled all thumbnailing options, apart from the small image files, and those too are only available as a small icon… But I’m still curious how large that folder got…
I’m surprised that there doesn’t seem to be a setting to limit the size of the thumbnail cache… I just ran the command line you suggested and it erased over 300 MB of thumbnails.
My dad wrote a tiny little bash script for this and stuck it into ~/bin. Here’s what we use:
#! /usr/bin/bash
# clear local data cache
# rm ~/.thumbnails/{large,normal}/*
# Error:
# bash: /bin/ls: Argument list too long
find ~/.thumbnails/ -name ‘*.png’ | xargs rm
Of course you can just use the command as it is as apposed to making a bash script. 🙂
Smaller too. =)
Actually, now that I use Ubuntu, the script needs to be altered slightly. In order to allow this script to be used by anyone on your system, do this:
$ touch clearthb
$ nano clearthb
Paste the following into the file:
#!/bin/bash
# clear local data cache
# rm ~/.thumbnails/{large,normal}/*
# Error:
# bash: /bin/ls: Argument list too long
Write out the file (Ctrl + O, Enter), exit (Ctrl + X).
$ sudo chmod +x clearthb
$ sudo mv clearthb /usr/bin/
Done, now whenever you wish to clear your thumbnail cache, execute:
$ clearthb
🙂
It would be cool if you could parse this line as english, like:
$find ~/.thumbnails -type f -atime +7 -exec rm {} \;
find inside the hidden directory .thumbnails in your home dir for files who’ve last been acessed 7 or more days ago, and execute a remove command on them.
What’s the final \; for?
$ find ~/.thumbnails -type f -atime +7 -exec rm {}
find: missing argument to `-exec’
That is the error message on ubuntu 11.10 when the last \; is omitted.
Pascal, you are the man! Useful stuff.. Thanks.
Yeah, very useful stuff!
very cool. I feel that the best way to add this permanetly, is to add an alias to the command
find ~/.thumbnails -type f -atime +7 -exec rm {} \;
e.g.
alias clearth='find ~/.thumbnails -type f -atime +7 -exec rm {} \;'
Then all I have to type is clearth in the teminal. Of course, clearth can be whatever name you want. I chose clearth, because it is logical and it is not already a linux command.Aliases are very cool, and are a good way to execute commands that otherwise might have a lot of syntax to remember.
To make aliases permanent, you must edit two files:
.bashrc
and
.bash_aliases
First create .bash_aliases, if you don’t already have this file:
gedit .bash_aliases
Then add you aliases inside this file, each alias having its own line. Saved the file.Next, edit your .bashrc file:
gedit .bashrc
Find these lines:
Uncomment them, and save the file.#if [ -f ~/.bash_aliases ]; then
# . ~/.bash_aliases
#fi
Close gedit.
Lastly, type bash in the terminal to restart bash.
Now when you type your aliases, you will see that the command gets executed.
Isn’t linux cool?
Hope this helps anyone out there wondering about using aliases for long commands.
[…] I learned this command on Ubuntu Blog. The command clears out thumbnails in Nautilus, which after time, can accumulate a lot of disk space. […]
Fantastic hack – mind if I add it to my hack notebook wiki? I’ll add full credit on there.
http://www.flyingjelly.net/wiki
Feel free, Ben.
Sorry but i’m a newbie in the world of Linux, in wich cron file should i put that line of code ($find ~/.thumbnails -type f -atime +7 -exec rm {} \;)?
thanks.
Ricardo,
Use the command $crontab -e
to edit your cron jobs.
You can also use gnome-schedule (Universe) to manage your cron jobs.
I manage cron jobs through the cpanel interface – it’s simple and effective
[…] I learned this command on Ubuntu Blog. The command clears out thumbnails in Nautilus, which after time, can accumulate a lot of disk space. […]
would this command be similar/same for Kubuntu?
Monday cleaning tasks (Cron jobs)
Every Monday night I run a series of automated cron jobs to free up disk space and keep the system tuned. The jobs empty some temporary folders which is not really necessary, and often consumes a lot of disk space.
Access the cron job editor by typing …
[…] Nautilus según la Wikipedia [GNOME.org] Proyecto Nautilus clean up old thumbnails […]
Isn’t “find ~/.thumbnails -type f -atime +7 -delete” cleaner?
i cant build a program… and my boss said that maybe my pc crashes… what will i do now?
[…] faccia il suo sporco lavoro di ricreare tutte le thumbnails ora orientate correttamente. Qui un comodo scriptino per cancellare le thumbnail delle immagini che non sono state visualizzate di recente ( in questo modo si risparmia anche un po di spazio su […]
I didn’t save as much but it did help me out with some extra space. Thx
fantastic. it works perfectly!
4Gb over here…
“wipe -rfc .thumbnails” does the job for me. I added an icon for the command to the panel, so now it’s just one click, and the thumbnails are gone forever…..
thanks, 1.6gb of thumbs are gone!
[…] al leer imágenes desde Nautilus (GNOME) o Konqueror/Dolphin (KDE). El consejo lo conseguí en esta nota y paso a explicárselos […]
[…] Ubuntu blog Escrito el 26 de Abril del 2008 a las 20:47 § RSS § Trackback § Comentar § […]
[…] Vía: Ubuntu blog […]
I just freed 5GB with this command (although I set -atime to +60).
Awesome!
what about ~/.nautilus files? I know how to turn-off ~/.thumbnails from creating but how to turn off creating of these .XML files?
I’m writing a Python GTK application to delete obsolete thumbnails:
https://launchpad.net/corydoras
Cool script… but how about changing the values in
/desktop/gnome/thumbnail_cache/
with the Configuration Editor?
I had been using this method for a few years now, but recently found a program that does this and more, see http://bleachbit-project.appspot.com/
yhanks and cool script… but how about changing the values in
/desktop/gnome/thumbnail_cache/
with the Configuration Editor?
Actually, now that I use Ubuntu, the script needs to be altered slightly. In order to allow this script to be used by anyone on your system, do this:
Pascal, you are the man! Useful stuff.. Thanks.
antalya ev ilaçlama
Modification to remove files older than 30 days from .thumbnails directory for ALL USERS, to be used by root as a cron job:
find /home -regex “/home/[^/]*/\.thumbnails/.*” -type f -atime +30 -delete
I greatly enjoyed this post! It seems like you are truly dedicated to your topic, which is a much needed change. I see a lot of authors just putting up quick junk, which is unfortunate. Thank you for bringing this information out, it’s much appreciated!