Practical, hands-on ways to control how long files live in /tmp so services stay reliable. 04.12.2025 | reading time: 3 min Every Linux system accumulates temporary files; left unchecked they consume space or break services that expect certain files to persist; this guide shows concrete commands and config snippets to control /tmp cleanup with predictable results. Hands-on: remove old files safely Try this simple experiment to see how age-based cleanup works on /tmp; run the commands below to create two demo files, make one appear older, list them, remove files older than seven days, and list again: ```bash mkdir -p /tmp/demo touch /tmp/demo/newfile touch -d "10 days ago" /tmp/demo/oldfile ls -l /tmp/demo # remove files not modified in the last 7 days find /tmp/demo -mindepth 1 -mtime +7 -exec rm -rf {} \; ls -l /tmp/demo ``` Make it automatic with systemd or cron Persist a policy by creating a tmpfiles rule and letting systemd run it, for example drop a file `/etc/tmpfiles.d/tmp.conf` containing `d /tmp 1777 root root 7d` to remove entries older than seven days and enable the periodic job with `systemctl enable --now systemd-tmpfiles-clean.timer`, or use a cron job that runs a `find` command nightly if systemd is not used. Options that matter in practice Decide on age thresholds carefully: installers and long-running jobs sometimes store transient state in /tmp; use the sticky bit (mode 1777) to protect ownership semantics, consider mounting /tmp as tmpfs for performance (e.g. `tmpfs /tmp tmpfs mode=1777 0 0`), and avoid recursive, aggressive deletion rules that match sockets or lock files; test cleanup rules in a sandbox before rolling out system-wide. Per-user and security considerations Prefer per-user runtime directories (XDG_RUNTIME_DIR) for ephemeral sockets, restrict cleanup tools to not follow symlinks, and be mindful that secure deletion is not guaranteed on tmpfs; when security matters, combine permissions, systemd unit isolation, and careful age-based policies rather than brute-force deletion. Closing: tidy systems are reliable systems Set explicit, tested cleanup policies and automate them so temp growth never surprises a service; keep experimenting, document your rules, and if you want deep, exam-oriented training consider pursuing CompTIA Linux+ or LPIC-1 prep with intensive courses at bitsandbytes.academy to turn these skills into certified expertise. Join Bits & Bytes Academy First class LINUX exam preparation. filesystem utilities scripting boot-process troubleshooting