2
  1. In general, how can we clean /tmp for freeing up the space taken by non-needed files?

    Note that I once made a mistake by deleting everything under /tmp, and then after rebooting, my Ubuntu was broken. I guess it broke the OS by deleting some system or programs' temporary files created in /tmp and still in use. So now I ask what is some safe way to remove nonneeded files created by some programs? (I can recognize unneeded files created directly by myself, such as a file copied by me into /tmp, but not those not created directly by me even though ls may show my name as the creater).

  2. In particular, I ran a program called pdfbeads, it created some very big file(s) in /tmp (I suspect the file is /tmp/magick-HMwXHfQo which is 1.2GB),and then my / partition for/tmp ran out of space and the program aborted.

    Now my / partition is still filled up. How can I clean /tmp for freeing up the space taken by non-needed files?

OS: Ubuntu 12.04

Tim
  • 98,580
  • 191
  • 570
  • 977
  • Rebooting the machine should take care of stopping the services and then restart them accordingly. – Ramesh Dec 04 '14 at 04:04
  • Thanks, solution without rebooting? – Tim Dec 04 '14 at 04:08
  • From a quick glance most people look to see how long the files have been in the directory & delete things that haven't been used in 4 days now if you are using this on a server that is constantly running certain programs which use the `/tmp` directory this *could* cause problems. [This](http://unix.stackexchange.com/questions/11235/is-it-safe-to-rm-rf-tmp) has some explanation, but **tmpreaper**looks like it has a better way of checking to see if any file is being used at the time. [Link](http://www.ubuntugeek.com/tmpreaper-cleans-up-files-in-directories-based-on-their-age.html) here – No Time Dec 04 '14 at 04:26
  • 1
    `/tmp/magick-*` are usually temporary files created by IM (`imagemagick`). If IM exits with error those files will not be automatically removed so you'll have to remove them manually. Other than that, see the question linked by @NoTime. – don_crissti Dec 04 '14 at 04:27
  • If `/tmp` is a tmpfs mount, turn on the atime mount option, and delete files with an atime more than 24 hours ago. – phemmer Dec 04 '14 at 05:07
  • @Patrick: how can I know if /tmp is a tmpfs mount? If yes, how to turn on the atime mount option? What if no? – Tim Dec 04 '14 at 05:09
  • @Tim `grep " /tmp " /proc/mounts` – Hauke Laging Dec 04 '14 at 07:27
  • @Tim - if `/tmp` *is* a tmpfs - and it almost definitely is - then you are probably barking up the wrong tree, im sorry to say - tmpfs is ephemeral - a ramdisk. you might like to know that you can increase the mounted size if needed with `sudo mount -t tmpfs -o remount,size=SIZE /tmp` if necessary - i usually use percent - as a percentage of available RAM - but you can do specific byte counts as well. – mikeserv Dec 04 '14 at 08:03

1 Answers1

2

Rebooting the system or restarting the failed services should solve the problem. There is probably no way to "repair" a running process which is missing its tmp file.

If you reboot the system often then you may just delete all (old) files in /tmp on boot. Otherwise you may use tools like tmpreaper.

Hauke Laging
  • 88,146
  • 18
  • 125
  • 174