Skip to main content

Ten Terminal Habits That Prevent Disasters

Carl HamiltonBy Carl HamiltonFounder, Hamilton Group
1 Aug 2026
Media Ten Terminal Habits That Prevent Disasters

 

The command line is powerful because it removes friction.

You can:

modify thousands of files

change permissions recursively

deploy applications

restart services

administer remote servers

automate repetitive jobs


with a few commands.

Unfortunately, that same efficiency applies to mistakes.

A command can be perfectly valid and still be disastrous because:

you ran it on the wrong server

you were in the wrong directory

a variable was empty

a wildcard matched more files than expected

you used administrator privileges unnecessarily

you copied a command without understanding it


Safe terminal work is therefore not about typing slowly.

It is about creating a few deliberate checks between:

intention → command → execution

Here are ten habits that dramatically reduce the chance of turning a routine terminal session into an incident.

1. Confirm Which Computer and User You Are Controlling

Before an important change, establish where you actually are.

On Linux or macOS:

hostname
whoami
pwd

On PowerShell:

hostname
whoami
Get-Location

This sounds almost too simple to mention.

It isn't.

When several SSH, PowerShell or terminal windows are open, it is surprisingly easy to think you are working on:

test-server

when the shell actually belongs to:

production-server

The command itself can be flawless.

The target is wrong.

For high-impact work, get into the habit of confirming:

machine → account → directory

before execution.

2. Inspect the Target Before You Modify It

Never let the destructive command be the first time you inspect its target.

Before something such as:

rm -rf /srv/application/cache/*

check:

ls -la /srv/application/cache/

Before recursively changing permissions:

find /srv/application -maxdepth 2 -ls

Before deleting files older than 30 days:

find /var/tmp -type f -mtime +30 -print

Review the output.

Then, only if it is correct:

find /var/tmp -type f -mtime +30 -delete

This is one of the best habits in command-line administration:

list first, modify second.

3. Use Dry Runs and Preview Modes

If a tool can show you what it intends to change, use that capability.

For rsync:

rsync -aHAXn --delete /source/ /destination/

The -n option performs a dry run.

This is particularly important with:

--delete

because a source/destination mistake can otherwise remove large amounts of data.

For PowerShell, many potentially destructive cmdlets support:

-WhatIf

For example:

Remove-Item "C:\Old Data\*" -Recurse -WhatIf

And where supported:

-Confirm

Microsoft explicitly designs -WhatIf to show what a command would do without carrying out the change, while -Confirm allows the operator to approve it before execution.

The principle works regardless of shell:

preview whenever the software allows it.

4. Read Commands Before Pasting Them

Do not treat terminal commands copied from:

forums

AI responses

documentation

Stack Overflow

GitHub

blog posts


as magic incantations.

Understand at least:

What program runs?

What files or settings does it touch?

Does it elevate privileges?

Does it download or execute anything?

Can it delete or overwrite data?

Be particularly cautious with constructions such as:

curl https://example.com/install.sh | sudo bash

That downloads content and sends it straight into a privileged shell.

A safer approach is:

curl -o install.sh https://example.com/install.sh
less install.sh

Then, if you understand and trust it:

chmod +x install.sh
sudo ./install.sh

Even a reputable source can contain:

obsolete instructions

mistakes

assumptions that do not match your environment


Reading before executing gives you a chance to catch them.

5. Quote Paths and Variables

Shell expansion causes a remarkable number of avoidable mistakes.

Suppose your directory is:

Client Files

This:

rm -rf Client Files

does not refer to one directory.

The shell sees two arguments:

Client
Files

Use:

rm -rf "Client Files"

The same principle matters even more with variables.

Unsafe:

rm -rf $TARGET

Safer:

rm -rf -- "$TARGET"

Quoting helps prevent:

whitespace splitting

wildcard expansion

surprising argument interpretation


The -- also tells many Unix tools that subsequent arguments are filenames rather than command options.

GNU Coreutils documents this specifically for filenames beginning with -.

6. Treat Wildcards as a Question, Not an Answer

Wildcards are convenient:

rm *.log

But before deleting the match, inspect it:

printf '%s\n' ./*.log

or:

ls -ld -- ./*.log

Now ask:

Are these exactly the files I meant?

This is especially important with recursive commands.

GNU rm includes protection against recursively deleting / by default, but that safeguard should not create false confidence. Other dangerous path mistakes remain possible, and GNU itself documents additional protections such as --one-file-system and --preserve-root=all for certain scenarios.

Do not rely on the tool rescuing you from an incorrect target.

Verify the target yourself.

7. Use the Least Privilege Necessary

Do not automatically prepend:

sudo

because a command failed with:

Permission denied.

That error may be telling you something useful.

Ask:

Should my normal account have access?

Is the ownership wrong?

Am I editing the correct file?

Does this operation genuinely need root access?


Running a command with elevated privileges increases the size of any mistake.

Compare:

rm wrong-file

with:

sudo rm wrong-system-file

The second command can affect the entire computer.

Similarly, avoid routinely running:

editors

development tools

browsers

scripts


as root or Administrator.

Use elevated privileges for the specific administrative operation that needs them.

Then return to your normal account.

8. Make a Rollback Before a Risky Change

Before editing an important configuration file, know how you will undo the change.

For example:

sudo cp -a /etc/nginx/nginx.conf \
 "/etc/nginx/nginx.conf.backup-$(date +%F-%H%M)"

Then make the change.

For larger systems, the rollback might instead be:

configuration management

version-controlled configuration

VM snapshot

filesystem snapshot

verified backup

deployment rollback


The exact mechanism is less important than the principle:

Know how to return to the previous known-good state before changing the current one.

Also be careful with version control around system configuration.

Do not casually initialise repositories containing:

passwords

private keys

API tokens

certificates


that might later be pushed somewhere inappropriate.

9. Validate Before Restarting the Service

Many services can check configuration syntax before you reload them.

Use that capability.

Nginx:

sudo nginx -t

OpenSSH:

sudo sshd -t

Apache on Debian/Ubuntu:

sudo apache2ctl configtest

Samba:

testparm

systemd unit:

sudo systemd-analyze verify /etc/systemd/system/example.service

For /etc/fstab:

sudo findmnt --verify

Why intentionally discover a syntax error during:

service restart

when you can discover it safely during:

configuration validation?

The safest sequence is:

edit → validate → reload/restart → verify.

10. Keep a Recovery Route Open

This is one of the most important habits when administering remote systems.

If you are changing:

SSH

firewall rules

networking

VPN

authentication

routing

storage mounts


do not destroy your only working connection before you know the replacement works.

Suppose you change SSH configuration.

Run:

sudo sshd -t

Keep the existing SSH session open.

Open a second connection.

Confirm it works.

Only then close the first session.

For critical remote infrastructure, also know whether you have access to:

hypervisor console

cloud-provider console

IPMI/iDRAC/iLO

physical console

rescue environment


A second terminal session is useful.

Out-of-band access is better.

Bonus Rule: Stop When Reality Disagrees With Your Plan

You expected:

3 files deleted

and the screen starts rapidly scrolling through hundreds of paths.

Stop.

For many terminal commands:

Ctrl+C

interrupts the process.

Then inspect what happened.

On Unix-like shells:

echo $?

shows the exit status of the previous command.

For a service:

systemctl status example.service

and:

journalctl -u example.service

can explain what went wrong.

Continuing blindly because:

“There are four commands left in the guide”

is one of the easiest ways to turn a small error into a large incident.

Unexpected output is not an inconvenience.

It is a signal to reassess.

Be Careful With set -euo pipefail

You will frequently see Bash scripts begin with:

set -euo pipefail

These options can be useful.

But they are not a substitute for proper error handling.

Broadly:

-u

helps catch unset variables.

pipefail

helps ensure a pipeline reports failures from commands other than the last one.

-e, however, has context-dependent behaviour and should not simply be treated as:

“make my script safe.”

For important automation, use explicit validation around dangerous operations.

For example:

if [[ -z "${BACKUP_DIRECTORY:-}" ]]; then
   echo "Backup destination is not set" >&2
   exit 1
fi

And before a destructive operation:

if [[ "$TARGET_DIRECTORY" == "/" ]]; then
   echo "Refusing to operate on /" >&2
   exit 1
fi

Better still, restrict the allowable target:

case "$TARGET_DIRECTORY" in
   /srv/application/cache/*)
       rm -rf -- "$TARGET_DIRECTORY"
       ;;
   *)
       echo "Unexpected target: $TARGET_DIRECTORY" >&2
       exit 1
       ;;
esac

The script should prove that its assumptions are true before performing destructive work.

Keep Secrets Out of Commands

Avoid:

some-tool --password SuperSecretPassword

Command-line arguments may be exposed through:

shell history

process listings

logging

monitoring tools


Prefer:

secure prompts

secret stores

credential managers

appropriately protected configuration

environment mechanisms designed by the application


And if you accidentally expose a real secret on the command line:

rotate or revoke it.

Deleting one line from shell history does not prove the secret was never captured elsewhere.

One Safe Workflow for Important Changes

For high-impact terminal work, I would use this sequence:

1. Confirm the computer.
2. Confirm your user.
3. Confirm the working directory.
4. Inspect the target.
5. Take a backup or establish rollback.
6. Preview the change.
7. Apply the smallest possible modification.
8. Validate the configuration.
9. Test the result.
10. Keep recovery access available.
11. Review logs.
12. Document what changed.

That sounds slower than simply typing the command.

In practice, it is much faster than recovering from:

the wrong files being deleted

or:

a remote server you have just locked yourself out of.

The Ten Habits at a Glance

The ten habits worth remembering are:

1. Confirm the machine, user and directory.


2. Inspect targets before changing them.


3. Use dry runs and -WhatIf where available.


4. Read commands before pasting them.


5. Quote paths and variables.


6. Preview wildcard matches.


7. Use the minimum privileges required.


8. Have a rollback before making the change.


9. Validate configuration before restarting services.


10. Keep recovery access open and stop when output looks wrong.

 

The principle behind all ten is the same:

Make the computer prove your assumptions before you give it permission to make the irreversible change.

How Hamilton Group Can Help

Command-line administration is extremely useful for:

Windows

Linux

servers

networking

automation

Microsoft 365

cloud infrastructure


but high-impact changes need proper planning, testing and recovery.

Hamilton Group can help businesses with:

Windows and Linux support

server administration

PowerShell

infrastructure automation

cloud services

networking

backup and disaster recovery

managed IT support


For business-critical infrastructure, the objective is not simply to have engineers who know powerful commands.

It is to use those tools with validation, least privilege, rollback and recovery built into the process.

Visit hgmssp.com or call 01423 438 953.

Carl Hamilton
About the author
Carl Hamilton
Founder, Hamilton Group
Carl Hamilton is the founder of Hamilton Group, a UK managed IT services provider helping small and medium businesses stay secure, productive and well supported with proactive IT, cyber security and Microsoft 365 expertise.

0 comments

  1. Be the first to comment.

Join the conversation

Comments are checked before they appear.

Your email stays private; we never publish it. By commenting you agree to our acceptable-use terms.