To answer the questions:
/tmp supposed to be emptied automatically: Yes
- Are we supposed to delete Files in
/tmp regularly and manually: No, your system will take care.
If you may ask yourself:
- Can I delete files from
/tmp for whatever reason (need space, want to remove traces, etc.): It depends, read on.
Filesystem Hierarchy Standard (FHS) states:
The /tmp directory must be made available for programs that require
Programs must not assume that any files or directories in /tmp are
preserved between invocations of the program.
/var/tmp/ has a simmilar purpose, but must not be deleted during reboot.
It is not guarantied that
/var/tmp/ are cleaned up on a regularly basis. This may depend on your distribution and settings, although most systems do some cleanup from time to time. See comment by
If you need to to delete a file in /tmp, see first if the file is in use. You can do this easily with:
If you have rights to do so, this will show the process holding the handle to that file, like process name, PID and type of the file. To show really all processes, prepend
sudo or run as user root.
lsof +D /tmp
will show you all files in
/tmp and directories below (
+D) that are currently open.
Of course you should not delete these files.
In fact when you delete a file that is still opened - if you have the rights to do so -, it becomes inaccessible from the filesystem namespace, but it still exists for the processes that have an open file handle for it. After closing that handle, the file is not accessible for that process any more, and if no process has the file opened any more it is finally deleted. A process should not suppose that the file survives between subsequent
open calls, but programmers are sloppy, and you never know. For that reason it's not that clever to delete files that are still in use by some programs.