This is something I used to do a lot on Windows, but after my recent fiasco I want to make sure. Is it safe to do
sudo rm -rf /tmp/*
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
In general, no.
If it's filling up with junk, you may want to look at what software isn't cleaning up after itself.
You can also use find to identify files which haven't been modified or accessed in a long time that are probably safe to delete.
The real answer is - it depends. /tmp may be used by applications that require lockfiles or temporary logs to be present in order to run, or it may not. There may be symlinks in there...not sure what for, but it's always possible.
You should really look at what is in there before you decide to remove it. doing an rf -rf * on anything is inherently dangerous.
No. For example, if you have a MySQL database running on your computer that will kill its socket, or if you are using emacs as a server that will kill the server process. There are many other cases where it is not safe to remove these files. The best thing to do is to write a script which checks the date of the file and only removes it if it is old.
Please use tmpreaper.
But you could a ramdisk for the /tmp dir then it would be empty after every reboot of the system. And as a side effect your system may become a little big faster.
Google has a lot on info on tmpfs and/or ramfs.
My suggestion is to rename your tmp folder first to see what's being affected by this directory. Rename it from "tmp" to "old_tmp". Also, create a new empty folder with name "tmp" because may some setup or system process require this folder to create some files inside this directory like log files. Follow these steps for secure removing of tmp date.
1- Rename existing "tmp" directory as "old_tmp". 2- Create new empty "tmp" directory 3- Assign all permission as "0777" to this newly created directory so the system/setup can have permission to create/place log and other files inside this directory. 4- Run system and applications to make sure everything is running fine and behaving as usual. Keep in observation for 2-3 days. 5- If sure nothing is affected due to renaming your "tmp" directory to "old_tmp" then you can delete "old_tmp" directory.
Note: If anything causing issue's due to renaming "tmp" directory to "old_tmp" then let this directory back to its original "tmp" name.