linuxbashfilesystemstmp

linux /tmp folder + how to know if files will deleted after reboot or after some time


I have Linux red-hat machine And I not sure what the concept about the directory /tmp

How to know if the files under /tmp will deleted after reboot or maybe will deleted after some time

Which file/configuration in my Linux machine responsible for that ? And if it possible to change the rules there?

remark my crontab is empty - no deleted Job there


Solution

  • This is specified in the File Hierarchy Standard and Linux Standard Base

    /tmp/ is often tmpfs mounted, and on systems where it is not the case, the boot init scripts should (and usually do) clean it.

    So files under /tmp/ do not survive a reboot. Put them elsewhere (perhaps /var/tmp/) if you want them to survive a reboot.


    In the FHS §2.3:

    The /tmp directory must be made available for programs that require temporary files.

    Programs must not assume that any files or directories in /tmp are preserved between invocations of the program.

    Tip Rationale

    IEEE standard P1003.2 (POSIX, part 2) makes requirements that are similar to the above section.

    Although data stored in /tmp may be deleted in a site-specific manner, it is recommended that files and directories located in /tmp be deleted whenever the system is booted.


    So unless your systems are very badly misconfigured, you should presume that /tmp/ is cleaned at least at reboot time. BTW, some sysadmins are setting a crontab entry to clean old files (e.g. weekly clean older than 2 weeks file). See also tmpfiles.d(5), TMPDIR, mkstemp(3), crontab(5), POSIX tmpfile & tmpnam