Lesson 12 · tested on Debian 13
rsync instead of cp: copy only what changed, dry-run first, and the trailing-slash trap
Use rsync instead of cp to keep a copy of a folder up to date: copy with -a, see exactly what changed with -i, preview deletions with a dry run (-n) before using --delete, learn the trailing-slash rule that decides whether you get a nested folder, and skip temporary files with --exclude.
Video coming soon — @ShellProven
Commands
Exactly as run in the video. Full folder with setup script and log: terminal-tutorials/rsync-instead-of-cp.
# The first copy: rsync -a
$ find photos -type f | sort
photos/2026/a.jpg
photos/2026/b.jpg
photos/2026/c.jpg
photos/cache/thumbs.tmp
photos/notes.txt
photos/old.txt
$ rsync -a photos/ backup/
$ find backup -type f | sort
backup/2026/a.jpg
backup/2026/b.jpg
backup/2026/c.jpg
backup/cache/thumbs.tmp
backup/notes.txt
backup/old.txt
# Only what changed: -i
$ echo "Day 2: rain" >> photos/notes.txt && rsync -ai photos/ backup/
>f.st...... notes.txt
$ rsync -ai photos/ backup/ && echo "nothing to copy"
nothing to copy
# Deletions: dry run first
$ rm photos/old.txt && rsync -ai photos/ backup/ && ls backup
.d..t...... ./
2026
cache
notes.txt
old.txt
$ rsync -ain --delete photos/ backup/
*deleting old.txt
$ ls backup
2026
cache
notes.txt
old.txt
$ rsync -ai --delete photos/ backup/ && ls backup
*deleting old.txt
2026
cache
notes.txt
# The trailing-slash trap
$ rsync -a photos/ copy1/ && ls copy1
2026
cache
notes.txt
$ rsync -a photos copy2/ && ls copy2
photos
# Skip files with --exclude
$ rsync -ai --delete --exclude='*.tmp' --exclude=cache/ photos/ clean/
created directory clean
cd+++++++++ ./
>f+++++++++ notes.txt
cd+++++++++ 2026/
>f+++++++++ 2026/a.jpg
>f+++++++++ 2026/b.jpg
>f+++++++++ 2026/c.jpg
$ find clean -type f | sort
clean/2026/a.jpg
clean/2026/b.jpg
clean/2026/c.jpg
clean/notes.txt
Quick check
Same two questions as in the video. Checked here, in your browser — nothing is sent anywhere.
Transparency. Script and narration made with AI, human-reviewed. The robot and the dog are AI-generated cartoon characters. The commands and their output are real runs in a container.