Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
rizhas@rizhas-laptop:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda7        67G   58G  5,2G  92% /
none            4,0K     0  4,0K   0% /sys/fs/cgroup
udev            1,5G   12K  1,5G   1% /dev
tmpfs           303M  1,2M  302M   1% /run
none            5,0M     0  5,0M   0% /run/lock
none            1,5G  348K  1,5G   1% /run/shm
none            100M   80K  100M   1% /run/user
overflow        1,0M  1,0M     0 100% /tmp
overflow        1,0M  1,0M     0 100% /tmp

How to clean up /tmp?

share|improve this question
Probably answered on Unix & Linux. Not sure whether that makes this question a duplicate. – drc Nov 21 '13 at 8:11
nope @drc but good find. I used a link from there to update my answer. – Rinzwind Nov 21 '13 at 8:31

You can assume that anything inside a tmp directory (/tmp/ /usr/tmp etc) can be deleted. BEFORE you start deleting stop all programs and services you are using since /tmp/ can be used by programs to temporarily store information for that session. So do a sudo service mysql stop and sudo service apache2 stop if you have a mysql and/or apache running. The name of the files in the /tmp/ directory most times give a clue to what program they belong.

So from command line...

cd /tmp/
sudo rm -r *

will empty the /tmp/ directory and remove all files and subdirectories. Be careful to type it correctly. The command pwd in there is obsolete but should show /tmp.

If you want it interactively (so you need to confirm deleting):

cd /tmp/
sudo rm -ri *

Also worth noting that a reboot will clear /tmp aswell as shown here: How is the /tmp directory cleaned up? So if /tmp/ is full of files after a reboot you need to investigate where those files originate from.

I also would like to state that 1 Mb for /tmp is not a lot of space. Are you using MySQL? See on how to fix this (thanks @drc)

share|improve this answer
the "without any harm" is true for files dating from before the last reboot. Otherwise it could be in use by a current program and (for that program) may cause issues... for example I have scripts that create files in /tmp, and then re-reads them to do the next step(s) of processing. deleting/truncating them in between will disrupt the program's actions (and could even lead to dangerous outcomes, depending what those files are used for) – Olivier Dulac Nov 21 '13 at 13:11
... so using a who –b (date of last boot), and then creating a file /boottime dated at the time of booting ( touch ....... /boottime), will allow one to do a safe find /tmp -type f \( ! -newer /boottime \) -delete \;, deleting only files older than the last boot – Olivier Dulac Nov 21 '13 at 13:19
May I use these comments to expand the answer? Mind you: the /tmp here is probably from mysql. – Rinzwind Nov 21 '13 at 13:27
As a person using mktemp regularly in my scripts, I strongly disagree with the "without any harm" statement. – hakermania Nov 21 '13 at 13:29
If /tmp contains anything older than the last reboot, then the startup scripts haven't done their jobs. – Simon Richter Oct 1 '14 at 13:55

/tmp is supposed to be cleaned up on reboot, but if you don't reboot (which is normal for servers), clean up will not happen

find /tmp -ctime +10 -exec rm -rf {} +

will delete all files and folders older than 10 days. you may want to add it to the daily cron.

share|improve this answer

The directory /tmp means temporary.

This directory stores temporary data. You don't need to delete anything from it, the data contained in it gets deleted automatically after every reboot.

Still if you want to delete the data present in it use

sudo rm -r /tmp/*

deleting from it won't cause any problem as these are temporary files.

share|improve this answer
They are temporary in the sense that they're not needed after rebooting, it doesn't mean they're not needed right now or that they won't be needed in 5mins – Daniel Serodio Sep 23 '15 at 20:21
It is not true that this "won't cause any problem." I did this once before I knew better and basically hosed my machine. – Kyle Strand Oct 27 '15 at 17:09
Also see – Kyle Strand Oct 27 '15 at 17:12

The tmpreaper program can be used to clean up /tmp periodically. This program deletes everything that has not been accessed in a given timeframe, typically two weeks. For this to work properly, the filesystem it is on should have the atimes option enabled. If you use a tmpfs, which it appears you are doing, then you should be fine.

Of course, rebooting also clears /tmp, but that would be boring.

share|improve this answer

The /tmp directory is cleared by default at every boot, because TMPTIME is 0 by default.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.