Clean up files older than two days in `/tmp/app-cache`, owned by `app`, where filenames may contain spaces and newlines.
BeginnerScenarioScenarios: backups, log rotation and housekeeping
Answer
Situation read → Let find select and delete; no parsing of names is needed.
What I'd do →
find /tmp/app-cache -xdev -type f -user app -mtime +2 -print -delete
find /tmp/app-cache -xdev -mindepth 1 -type d -empty -delete
-xdevstays on one filesystem;-printlogs what was deleted.-deletehandles any filename because no shell orxargssplitting is involved.- Alternatively, declare it with systemd-tmpfiles:
d /tmp/app-cache 0750 app app 2din/etc/tmpfiles.d/app.conf.
Why → The safest way to handle weird filenames is to never turn them into text.
Interview tip → Mention systemd-tmpfiles; many teams forget it exists and write cron jobs instead.
More on Scenarios: backups, log rotation and housekeeping
Design a nightly backup of `/etc` and application data to S3 with retention.IntermediateWrite the core of a Postgres backup that streams `pg_dump` through gzip to S3 and never uploads an empty dump.IntermediateBackups have "succeeded" every night for a year, but the first real restore failed. How do you make backups trustworthy?Advanced`/var` is 100% full because an app's logs were never rotated, and the app now fails to start. What do you do now, and what do you set up after?BeginnerShould you use `copytruncate` or a `postrotate` signal for an application's logs? How do you decide?Intermediate`/srv/app/releases` has 300 old release directories. Write a cleanup that keeps the newest 5 and never deletes the current release.Beginner