I am using Ubutu 10.04. I have some apps that create a few temporary files in /tmp/<file>
as part of their shutdown process. I want to inspect those files when the apps are closed in the event of a system shutdown. However, when the system comes up again I find that all temporary files have been deleted. How can I ask the system not to clear the files in /tmp/
on shutdown?

- 137
- 1
- 4
4 Answers
/tmp
is often an in memory file system so once you reboot, it's gone.
Instead of trying to preserve /tmp
, I would try to get my processes to write to a different directory. If they are written well, the apps should honor the TMPDIR environment variable to decide where to write temp files; you can then have it point to another directory such as /var/tmp
which should survive a reboot.
You can define when files from /tmp
can be deleted. You should change the value of TMPTIME
variable form /etc/default/rcS
file.
The default value of these variable is 0
- these means that files will be deleted every time computer starts. Set up TMPTIME
to 3
means that will delete files older than 3 days.
But you can set TMPTIME=infinite
- these means that the files will be never deleted.

- 324
- 2
- 8
-
Since my requirement is to inspect the files for debugging purposes, this solution works best for me. – 341008 Oct 23 '14 at 16:29
-
Not working in 16.04 - tried a number as well as `infinite`, but the files keep on getting deleted. Is there any configuration command to be run after this for the change to take effect? – Janaka Bandara Apr 25 '19 at 01:50
you could change the times that files in /tmp have to be modified in order to delete them. but if you configure your linux distro to keep the files /tmp for ever and/or a long time then you hard disk will be filled with useless (or not) files in /tmp directory .. take a look here
-
Taking into account the comment about /tmp being mounted as a "ramdisk" (aka tmpfs), use the `mount` command to make sure your system wasn't configured that way. – pcapademic Jun 02 '10 at 18:40
Is it possible to change where those apps store the temporary files?
A better approach would be to store those files in /var/tmp
, which is specifically designed for this.

- 141
- 4