Back to commands

Dangerous Commands

Dry run / preview

Preview What Rsync Would Delete

You need to know which files rsync would delete before running a real sync.

Command

rsync -avhn --delete ./source/ ./backup/ | grep '^deleting'

Before you run this

System impact: Preview only. Still verify source and destination paths before running the real command.

When not to use it: Do not remove `-n` until paths and direction are confirmed.

Expected output

Lines showing files that would be deleted.

System impact

Dry run / preview. Nothing changes because `-n` performs a dry run.

When to use it

Use this before allowing rsync to delete anything.

When not to use it

Do not remove `-n` until paths and direction are confirmed.

Recovery / rollback

No state is changed during the dry run.

Watch this command run

Command transcript

This sanitized transcript shows the commands and output shape without exposing host details.

demo@lab:~$

$ find source backup -maxdepth 2 -type f | sort

backup/app.conf
backup/stale.txt
source/app.conf
source/index.html

$ rsync -avhn --delete ./source/ ./backup/

sending incremental file list
deleting stale.txt
app.conf
index.html

sent 101 bytes  received 31 bytes  264.00 bytes/sec
total size is 24  speedup is 0.18 (DRY RUN)

$ rsync -avhn --delete ./source/ ./backup/ | grep '^deleting'

deleting stale.txt
View commands shown

These are the commands shown in the sanitized transcript.

Commands shown

  1. find source backup -maxdepth 2 -type f | sort
  2. rsync -avhn --delete ./source/ ./backup/
  3. rsync -avhn --delete ./source/ ./backup/ | grep '^deleting'

next steps

Related commands

Hosting Operations Dry run

Preview Backup Drift with rsync

Rsync can tell you what would change before it changes anything.

rsync -ain --delete source/ backup/
Dangerous Commands Deletes data

Print a Dry-Run Removal Script

The reviewable cleanup command is the one you print before you run.

find /lab/disk-inode-cleanup/var/tmp/uploads -xdev -type f -mtime +7 -printf 'rm -i -- %p\n'
Hosting Operations Can be slow

Compare Source and Backup File Lists

A backup can be missing files and still look plausible at a glance.

comm -3 <(find source -type f | sed 's#^source/##' | sort) <(find backup -type f | sed 's#^backup/##' | sort)
Study mapping

Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.

  • lpic1:103-gnu-unix-commands
  • lpic1:104-filesystems-permissions-fhs
  • lfcs:essential-commands
  • lfcs:operations-deployment
  • lfcs:storage
  • linuxplus:automation-scripting
  • linuxplus:provisional
  • linuxplus:troubleshooting
  • risk:dry-run

Useful for

  • LPIC-1 style command-line practice
  • LFCS style performance tasks
  • Linux+ style troubleshooting review

Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.