<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://leo.leung.xyz/wiki/index.php?action=history&amp;feed=atom&amp;title=Linux_%2Ftmp</id>
	<title>Linux /tmp - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://leo.leung.xyz/wiki/index.php?action=history&amp;feed=atom&amp;title=Linux_%2Ftmp"/>
	<link rel="alternate" type="text/html" href="https://leo.leung.xyz/wiki/index.php?title=Linux_/tmp&amp;action=history"/>
	<updated>2026-11-17T02:09:36Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://leo.leung.xyz/wiki/index.php?title=Linux_/tmp&amp;diff=7398&amp;oldid=prev</id>
		<title>Leo: Created page with &quot;Temporary files on Linux can be stored in various places. See [https://www.freedesktop.org/software/systemd/man/file-hierarchy.html file-hierarchy(7)] for details about these two (and most other) directories of a Linux system. {| class=&quot;wikitable&quot; ! !/tmp !/var/tmp !/run !/run/user/# !/dev/shm |- !Typical behavior |not preserved between reboots Periodic cleanup may occur. |typically preserved between reboots. Periodic cleanup may occur. |for non-persistent runtime data o...&quot;</title>
		<link rel="alternate" type="text/html" href="https://leo.leung.xyz/wiki/index.php?title=Linux_/tmp&amp;diff=7398&amp;oldid=prev"/>
		<updated>2023-11-17T00:06:03Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Temporary files on Linux can be stored in various places. See [https://www.freedesktop.org/software/systemd/man/file-hierarchy.html file-hierarchy(7)] for details about these two (and most other) directories of a Linux system. {| class=&amp;quot;wikitable&amp;quot; ! !/tmp !/var/tmp !/run !/run/user/# !/dev/shm |- !Typical behavior |not preserved between reboots Periodic cleanup may occur. |typically preserved between reboots. Periodic cleanup may occur. |for non-persistent runtime data o...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Temporary files on Linux can be stored in various places. See [https://www.freedesktop.org/software/systemd/man/file-hierarchy.html file-hierarchy(7)] for details about these two (and most other) directories of a Linux system.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!&lt;br /&gt;
!/tmp&lt;br /&gt;
!/var/tmp&lt;br /&gt;
!/run&lt;br /&gt;
!/run/user/#&lt;br /&gt;
!/dev/shm&lt;br /&gt;
|-&lt;br /&gt;
!Typical behavior&lt;br /&gt;
|not preserved between reboots&lt;br /&gt;
Periodic cleanup may occur.&lt;br /&gt;
|typically preserved between reboots.&lt;br /&gt;
Periodic cleanup may occur.&lt;br /&gt;
|for non-persistent runtime data of long lived services such as locks, sockets, pid files &lt;br /&gt;
|Typically set as the &amp;lt;code&amp;gt;XDG_RUNTIME_DIR&amp;lt;/code&amp;gt;. &lt;br /&gt;
Not preserved between reboots&lt;br /&gt;
|A memory backed scratch space for programs.&lt;br /&gt;
Not preserved between reboots&lt;br /&gt;
|-&lt;br /&gt;
!Typical fs&lt;br /&gt;
|tmpfs, backed by RAM/swap&lt;br /&gt;
|backed by persistent filesystem&lt;br /&gt;
|tmpfs, backed by RAM/swap&lt;br /&gt;
|tmpfs, backed by RAM/swap&lt;br /&gt;
|On Linux, typically tmpfs&lt;br /&gt;
|-&lt;br /&gt;
!Access&lt;br /&gt;
|Writable by everyone&lt;br /&gt;
|Writable by everyone&lt;br /&gt;
|Writable to only privileged services&lt;br /&gt;
|Writable to only its user&lt;br /&gt;
|Writable by everyone&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Typical mount options ==&lt;br /&gt;
&amp;lt;code&amp;gt;/tmp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;/var/tmp&amp;lt;/code&amp;gt; are typically mounted with the following options:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;noexec&amp;lt;/code&amp;gt; - no programs can be executed&lt;br /&gt;
* &amp;lt;code&amp;gt;nosuid&amp;lt;/code&amp;gt; - no setuid bits can be set&lt;br /&gt;
* &amp;lt;code&amp;gt;nodev&amp;lt;/code&amp;gt; - no device nodes&lt;br /&gt;
&lt;br /&gt;
In addition, all public temporary locations (including &amp;lt;code&amp;gt;/tmp&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;/var/tmp&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/dev/shm&amp;lt;/code&amp;gt;) are typically &amp;lt;code&amp;gt;chmod 1777&amp;lt;/code&amp;gt;. This grants anyone the ability to write there with new file&amp;#039;s ownership defaulting to the owner&amp;#039;s user and group.&lt;br /&gt;
&lt;br /&gt;
== Automatic cleanup ==&lt;br /&gt;
Automatic cleanup on systemd systems is done through the &amp;lt;code&amp;gt;systemd-tmpfiles&amp;lt;/code&amp;gt; service.&lt;br /&gt;
&lt;br /&gt;
== Bind mounting /tmp over /var/tmp ==&lt;br /&gt;
In some scenarios, it may make sense to bind-mount /tmp over /var/tmp. This forces temporary files to one location. Some advantages with this approach include:&lt;br /&gt;
&lt;br /&gt;
* Simplify where temporary files are located and cleaned up&lt;br /&gt;
* Reduce the risk of /var filling up&lt;br /&gt;
&lt;br /&gt;
This can be implemented by running &amp;lt;code&amp;gt;mount --bind /tmp /var/tmp&amp;lt;/code&amp;gt; or by adding to &amp;lt;code&amp;gt;/etc/fstab&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{Highlight&lt;br /&gt;
| code = /tmp /var/tmp none bind 0 0&lt;br /&gt;
| lang = text&lt;br /&gt;
}}&lt;/div&gt;</summary>
		<author><name>Leo</name></author>
	</entry>
</feed>