Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Special Files and Directories

The /run directory

Reference for /run: the tmpfs holding PID files, sockets, lock files and per-user runtime directories, XDG_RUNTIME_DIR, and why its contents vanish at reboot.

/run is a small in-memory filesystem (tmpfs) that holds runtime state: data that matters only while the system is up. Services put their PID files, Unix sockets and lock files here, and systemd keeps its own bookkeeping under /run/systemd. The whole directory is empty after every boot.

Because it is mounted early and is always writable, /run replaced the older practice of using /var/run and /var/lock; those names are now symbolic links to /run and /run/lock.

Terminal
ls /run
ls /run/user/$(id -u)
echo "$XDG_RUNTIME_DIR"

Try it

Bash A PID file in a run-style directory

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash A lock file so a script runs only once

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Path Contents
/run/NAME.pid or /run/NAME/NAME.pid PID of a running daemon.
/run/NAME.sock Unix domain socket for that service (for example /run/docker.sock).
/run/lock/ Lock files (formerly /var/lock).
/run/user/UID/ Private runtime directory for a logged-in user; $XDG_RUNTIME_DIR points here.
/run/systemd/ systemd state: transient units, resolve/, journal/.
/run/utmp Who is currently logged in (read with who).

Edge cases: a PID file can be stale after a crash: the file exists but the process does not. Always verify with kill -0 PID or /proc/PID. PIDs can also be reused by unrelated processes.

Usage notes

  • Not persistent. Anything you put here disappears at reboot. Configure services with RuntimeDirectory= in a systemd unit and systemd creates, owns and removes the folder for you.
  • Memory-backed: files use RAM. Keep them small; do not store logs or caches here.
  • Per-user directory: /run/user/1000 has mode 700, is created at login and removed at last logout. It holds the user's D-Bus socket, PulseAudio/PipeWire sockets and similar.
  • Sockets: access to a socket is controlled by file permissions. Giving a user access to /run/docker.sock is effectively giving root, so be careful.
  • Atomic locking: noclobber (as above), mkdir, or flock are safe; testing "if file does not exist then create it" in two steps is not.
  • Containers have their own /run; it does not show the host's services.