Linux Runtime and Persistent Data: /var, /run and /tmp
What you need to know
A file’s purpose and expected lifetime help determine its location. Persistent data is intended to survive ordinary restarts; runtime state describes a running system and may be recreated on startup. A pathname alone does not guarantee persistence, backup, or a particular storage medium.
How the layout works
/var is the usual location for changing application data. /var/log often holds logs; /var/lib commonly holds persistent service state; /var/cache contains data that applications can generally regenerate. Some logs may instead be volatile or remote. /run is for state needed during the current boot, such as a service socket (an endpoint for communication). /tmp is for temporary files and may be cleaned at restart or by policy. /var/tmp is conventionally for temporary data expected to last across reboots, but retention is still policy-dependent.
/opt is a conventional location for add-on software; /srv can hold data served by a service. /mnt is often used for temporary administrator mounts and /media for removable media. A mount attaches a filesystem to a path; the directory may exist without a filesystem mounted directly there.
Before practicing
Use a normal user in your disposable Linux lab with Bash, GNU Coreutils and util-linux. These examples inspect specific paths only; no sudo is needed. If a directory, command or permission is missing, record the difference and stop rather than changing the system. Ubuntu 24.04 LTS is the teaching baseline; the recorded local outputs are from Debian 13.3 in a container.
Compare conventional locations
ls -d /var/log /var/lib /var/cache /run /tmp /var/tmpEach existing path is listed. This checks presence only, not whether the data survives reboot or whether you can read the contents.
Find the filesystem behind a path
findmnt is a util-linux inspection tool. --target finds the filesystem containing the path, -n omits headings, and -o chooses columns. For example, / overlay means the path resides on the root overlay mount. tmpfs is another possible result. Neither tells you the cleanup policy.
Inspect a possible mount location
The output may show / rather than /mnt: the directory can exist without a separate filesystem attached at that point. Results depend on the machine.
A directory name is an address in the tree. A mount attaches a filesystem at a location in that tree, and the filesystem type describes its implementation. The retention policy is a separate decision. For example, a scratch directory can be on the same filesystem as persistent service data without having the same cleanup rules.
Common mistakes
Never keep your only copy of important work in /tmp. Do not delete /var/lib to free space or assume /var/log contains all logs. Use the actual service documentation and backup policy. findmnt here only inspects; mounting and unmounting are taught in a later chapter.
Try it yourself
Classify a persistent database file, a disposable scratch file, a service socket and a removable drive. Run findmnt -n -o TARGET,FSTYPE --target /run and explain what the output can and cannot tell you.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Runtime and persistent data — Knowledge Check
Apply Linux filesystem layout concepts and interpret safe inspection results.
Which is the best conventional location for persistent service state?
Which path is commonly used for a running service socket?
What does `/ overlay` from `findmnt -n -o TARGET,FSTYPE --target /tmp` tell you?
What is the safest place for your only copy of an important document?
A directory `/mnt` exists. What can you infer?