Ubuntu: How to clean tmp? (7 Solutions!)
Channel: Roel Van de Paar
Date: 28/06/2019

Ubuntu: How to clean /tmp?


Question: 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?

Solutions Sample (Please watch the whole video to see all solutions, in order of how many people found them helpful):

== This solution helped 10 people ==
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.

== This solution helped 1 person ==
If your “/tmp” mount on a linux filesystem is mounted as overflow (often sized
at 1MB), this is likely due to you not specifying “/tmp” as its own partition
and your root filesystem filled up and “/tmp” was remounted as a fallback. To
fix this after you’ve cleared space, just unmount the fallback and it should
remount at its original point:
sudo umount overflow
if device is busy use
sudo umount -l overflow

== This solution helped 2 people ==
The /tmp directory was cleared by default at every boot, because TMPTIME is 0
by default.

== This solution helped 32 people ==
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/
pwd
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 not necessary 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: https://
askubuntu.com/questions/20783/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 https://unix.stackexchange.com/a/76058/10017 on how to fix
this (thanks @drc)

== This solution helped 4 people ==
Be careful before running a command like rm -r ./*. Once you run it, it will be
very difficult or impossible to recover any data.
All will be removed. Make sure that the directory you are deleting in is right.
There is a safer way to handle things.
# sudo rm -r /tmp/*
That way, when you accidentally run this command from inside your shell
history, it won't delete the wrong files (unless you're keeping them in /tmp).

== This solution helped 7 people ==
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.

With thanks & praise to God! With thanks to the many people who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music: https://www.bensound.com/royalty-free-music | Images: https://stocksnap.io/license & others | With thanks to user Tarun (https://askubuntu.com/users/166815), user Simon Richter (https://askubuntu.com/users/10359), user Rizhas (https://askubuntu.com/users/73793), user Rinzwind (https://askubuntu.com/users/15811), user Mark Yisri (https://askubuntu.com/users/595510), user kiri (https://askubuntu.com/users/176889), user dessert (https://askubuntu.com/users/507051), user ck reddy (https://askubuntu.com/users/179260), user Avinash Raj (https://askubuntu.com/users/202806), user Andrei R (https://askubuntu.com/users/397556), and the Stack Exchange Network (http://askubuntu.com/questions/380238). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything should be amiss at Roel D.OT VandePaar A.T gmail.com.