GuardUtils

Why you should be using SysMD's GuardUtils

Four small, safety-first command-line tools that each solve a classic sysadmin jam: botched chmod, unbacked edits, unrecoverable rm, and dev cruft. By Marco D’Aleo, a colleague whose work I trust and recommend.

The common thread

Every sysadmin has a set of commands they run on muscle memory: chmod, chown, rm, editing config files in place. They’re the workhorses of the command line. They share one uncomfortable property: they’re irreversible. There’s no chmod --undo. There’s no rm --restore. There’s no way to get back the version of the file you had before you hit save in vi at 3 a.m.

Sure, you take backups (you do, right?) but those are only as useful as the intervals at which they run. I don’t know about you, but I make more than one mistake within a single window wherein no backup ran to save me!

Enter GuardUtils: a suite of four small Python tools by SysMD that each take one of those irreversible, mistake-prone operations and make it reversible, previewable, or - at minimum - recoverable. They don’t try to replace the tools you know. They wrap them, or sit alongside them, with a safety net underneath.

chguard: undo for chmod and chown

The classic sysadmin nightmare: a recursive chmod -R or chown -R against the wrong tree, and suddenly a service, a home directory, or /etc is hosed. Unix gives you no way back.

chguard snapshots filesystem ownership and permission bits before you act, previews any restore as a colourised diff table, and applies changes only after explicit confirmation. Its standout feature is wrapper mode - chguard -- chmod 755 file automatically snapshots the affected paths before running the command, so a one-liner gives you a free rollback point. It never creates, deletes, or moves files; it never follows symlinks; it refuses to run non-interactively without an explicit --yes. The scope is deliberately narrow - ownership and permissions only - and that narrowness is the point.

mirro: the editing habit you should already have

Marco puts it plainly: “have you ever been the ‘ugh, I forgot to back this up first’ situation? No? Stop lying.” Every sysadmin has edited a config file in place and then wished they had a copy of the original.

mirro wraps $EDITOR so that editing a file always goes through a temp-copy, compare, backup-before-overwrite pipeline. You type mirro /etc/fstab instead of vim /etc/fstab. If you change nothing, nothing happens - no spurious backup, no overwrite. If you do change something, the original is saved to ~/.local/share/mirro/ with a timestamp before the target is touched. Restore, diff, listing, and pruning are all built in. It’s one extra character to type, and it eliminates an entire class of regret.

resrm: rm that you can take back

Desktop environments have had trash semantics for decades. The command line - where most server file management actually happens - still has rm, and rm is a one-way door.

resrm is a drop-in replacement for rm that moves files to a per-user trash area instead of unlinking them. The familiar flags (-r, -f, -i) behave as expected. You can list, inspect, and restore trashed files by short ID or basename, with automatic pruning on a configurable retention window. Permanent deletion is opt-in via --skip-trash. When run under sudo, it puts files in their owner’s trash, not root’s - a small touch that makes natural sudo resrm ~alice/somefile workflows work without root acting as intermediary.

filedust: autoremove for files

The slow jam: __pycache__ directories, .pytest_cache, build/ and dist/ outputs, Vim swap files, .DS_Store - the cruft that silently fills a developer’s home directory and clutters searches and backups.

filedust scans under $HOME for unambiguous dev junk, renders a table showing exactly what it found and why, asks one confirmation, and deletes files-then-directories. It refuses any path outside $HOME, never follows symlinks, and treats user excludes as the always-wins escape hatch. User-configured include patterns let you extend the built-in rules for your own workflow. It’s the cleanup pass you’d do by hand with find and -delete, except safe, previewable, and repeatable.

I actually run filedust all the time. It’s quite useful in build scripts and workflows where you want to wipe out cruft before shipping something, or to stay conservative in terms of artifact sizes.

What unites them

The four tools share a design philosophy that is really why I wanted to write about it, because I think it’s rare in small CLI utilities:

  • Reversible by default, irreversible on demand. Trash, not unlink. Snapshot, not blind apply. Backup, not overwrite. The dangerous path is always opt-in.
  • Preview before mutate. Every tool shows you what it will do before it does it. --dry-run and confirmation prompts are first-class, not afterthoughts.
  • Fail-closed. If something can’t be done safely, the tool refuses rather than guessing. No TTY? Abort. No write access? Abort, and let the operator decide on sudo.
  • Never auto-escalate. None of these tools will run sudo for you. If elevated privileges are needed, they tell you and let you re-run. The operator stays in control.
  • Narrow scope. Each tool does one thing and explicitly documents what it does not do.

Marco the magnificent

GuardUtils is the work of Marco D’Aleo, who runs SysMD . Full disclosure! Marco is a colleague and another competent sysadmin consultant, who I’ve had the pleasure of mentoring and teaching a lot about ‘my way’ (yet he has developed his own way, which is a great thing). He has my backing for anyone who needs a contact sysaadmin in the European timezone and is happy to trust someone I trust.

The GuardUtils project reflects the person: careful, precise, and honest.

Where to find them

The full suite - source, packages, and documentation - is at guardutils.sysmd.uk . If you spend your day on the command line, install all four. The cost is a few megabytes of Python. The upside is never losing a file, a permission set, or a pre-edit config again!

At a glance
  • Author: Marco D’Aleo (SysMD)
  • Language: Python
  • License: GPL-3.0-or-later
  • Tools: chguard, mirro, resrm, filedust
  • Packaging: APT, RPM, PyPI
The four tools
  • chguard - undo for chmod/chown
  • mirro - safe file editing with backups
  • resrm - rm with trash and restore
  • filedust - dev cruft cleaner
Need a sysadmin in Europe?
If you need someone in the European timezone, I can introduce you to Marco, or visit his site!
Contact me