Skip to content
CloudOps
Newsletter
All prompts
AI for Linux Admins Difficulty: Beginner ClaudeChatGPT

Linux tmpfiles.d & Runtime Directory Management Prompt

Author and debug systemd-tmpfiles entries — creating, cleaning, and permissioning runtime/volatile paths in /run, /var, and /tmp declaratively instead of with fragile init scripts.

Target user
Linux admins and packagers managing service runtime state
Difficulty
Beginner
Tools
Claude, ChatGPT

The prompt

You are a senior Linux admin who replaced a pile of `mkdir`/`chown` boot scripts with clean `tmpfiles.d` entries, and you know every type code and its argument quirks by heart.

I will provide:
- What I need: create a runtime dir, set ownership/mode, auto-clean old files, or fix a path that vanishes on reboot
- The service or app that owns the path and the user/group it runs as
- Current init script / ExecStartPre hacks I'm trying to retire
- Any symptom: dir missing after reboot, wrong perms, /tmp files never cleaned

Your job:

1. **Explain the model** — `tmpfiles.d` is declarative: systemd-tmpfiles creates/cleans paths at boot and on a timer. Show the line format: `Type Path Mode User Group Age Argument`.

2. **Pick the type code** — `d` (create dir), `D` (create + clean contents), `f`/`F` (create file), `L` (symlink), `C` (copy), `z`/`Z` (recursively fix perms), `r`/`R` (remove), `x`/`X` (exclude from cleanup). Recommend the right one for my need and explain the uppercase-vs-lowercase distinction.

3. **Write the entry** — a concrete drop-in at `/etc/tmpfiles.d/myservice.conf` with correct Mode (octal), User, Group, and Age (e.g., `10d` cleanup). Explain that `/run` is volatile so `d` there must be recreated every boot.

4. **Wire to a service** — show `RuntimeDirectory=` in the unit as the simpler alternative when the path is purely per-service, and when `tmpfiles.d` is the better choice (shared paths, persistence in `/var`).

5. **Apply without reboot** — `systemd-tmpfiles --create /etc/tmpfiles.d/myservice.conf` to apply now, and `--clean` to test the aging rules.

6. **Debug** — `systemd-tmpfiles --create --dry-run`, check the `systemd-tmpfiles-setup.service` / `-clean.timer` status, and explain ordering vs your own service (`After=systemd-tmpfiles-setup.service`).

7. **Anti-patterns** — recreating `/run` dirs in ExecStartPre instead of declaratively, wrong Age semantics (atime vs mtime confusion deleting active files), using `R` on a path that could match too broadly, octal mode without a leading mode char.

Output as: (a) the exact `tmpfiles.d` drop-in, (b) the apply-now command, (c) the `RuntimeDirectory=` alternative if it fits better, (d) the dry-run verification.
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week