Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 207
maihabunash Avatar asked Jan 28 '26 16:01

maihabunash


2 Answers

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

like image 87
Basile Starynkevitch Avatar answered Jan 31 '26 07:01

Basile Starynkevitch


Just check the output of

mount

If you find that /tmp is of tmpfs type, then it will be deleted. tmpfs is an in-memory filesystem.

But never count on /tmp to persist.

like image 21
SzG Avatar answered Jan 31 '26 06:01

SzG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!