Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

CLI Tools That Support Previews, Dry Runs or Non-Destructive Actions

cli-tools-that-support-previews-dry-runs-or-non-destructive-actions.jpg

This isn't meant to be an exhaustive list, but a reminder to use these features if possible and to build them into your tools.

Quick Jump:

Prefer video? Here it is on YouTube.

Being able to see the output of something before it happens for real is helpful. For example, seeing a list of files / directories before you delete them when you’re using a regex pattern.

Also, when troubleshooting something, being able to preview the output of what a tool is parsing to provide its results helps so much.

# Previews

There’s a bunch of tools that have this but here’s 2 that come to mind:

Docker Compose is a great example of previews. You can run docker compose config to have compose parse your file, interpolate everything and provide you what it’s seeing as your final config. I’ve written about this in more detail in this Docker tip.

Terraform is also ok when it comes to previews by letting you plan your run instead of applying it so you can see a diff of what’s about to change. Terraform lets you provision your infrastructure (servers, etc.) through configuration. There’s subtle things that might be different between both a plan and apply that can only be discovered when you really do it, but it’s far better than nothing.

In any case, take advantage of these features when they exist because they can save you hours of time when troubleshooting or prevent disaster by accidentally deleting a production database instead of a pre-prod database by carefully inspecting the output of what a command is doing.

# Dry Runs

Like previews, a bunch of tools support this. Here’s a couple that you might use in your day to day, I know I do!

I use rsync to backup files to an external drive which I’ve written about in the past. I do this with the --delete flag to ensure my backup drive only contains the files on my main drive. This helps avoid a growing list of stuff that I do want to delete or have moved to a different directory. Running it with --dry-run lets me review what’s changing before it happens.

Various system package managers have this feature. For example apt supports --dry-run on a few commands which can be handy to see before running an upgrade or before installing packages. Arch Linux has a nice checkupdates utility dedicated to this too.

Sometimes package managers require you to press y to continue so you get a mini version of a dry run but there’s something comforting about running --dry-run as an extra level of protection since you could hit y out of habit and technically environment variables or other system configuration can auto-accept these prompts.

You can also get creative for tools that don’t have this built-in such as sed. Of course you can write its output to stdout to see the changes before you maybe inline update a file but you can also combine sed with diff to see how something changed.

For example diff -u <(echo "hello") <(echo "hello" | sed "s/hello/hi/g"):

--- /proc/self/fd/11    2025-08-23 10:06:31.117779548 -0400
+++ /proc/self/fd/12    2025-08-23 10:06:31.117779548 -0400
@@ -1 +1 @@
-hello
+hi

If you had a file that you’re doing a replacement on you can do diff -u myfile <(sed "s/old/new/g" myfile). I’ve done this type of thing quite a few times to better see how I’m changing a file. It’s our own home made preview / dry run!

Another one is deleting files. Instead of going guns glazing with rm -rf REGEX_PATTERN or using -i to step through each file (which might be annoying if there’s a lot of them), I’ll use find . -name "REGEX_PATTERN" to see what gets returned and when I’m happy with the results change the command to find . -name "REGEX_PATTERN" -delete to really do it.

The video below demonstrates some of these commands.

If you’re developing tools that have side effects or you parse things in complex ways, please add in these features so folks have insight into what’s happening. It helps a lot!

# Demo Video

Timestamps

  • 0:23 – Parsing your Docker Compose config
  • 1:28 – Terraform plan vs apply
  • 3:52 – rsync
  • 6:19 – System package managers
  • 9:19 – sed combined with diff
  • 11:31 – Deleting files and directories with find

When was the last time you got burned by not previewing? Let me know below.

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per year (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.



Comments