Bash Manipulation: Copy and Move Drill
Use cp and mv as a safe two-step flow for duplication, review, and final naming.
Start Interactive LessonThis lesson reinforces a production-safe sequence: copy first, verify, then move or rename to final state. It reduces risk during refactors and incident remediation.
Commands to Practice
mkdir -p copy-move-demo
printf '%s\n' 'Quarterly report' > copy-move-demo/report.txt
cp copy-move-demo/report.txt copy-move-demo/backup.txt
mv copy-move-demo/backup.txt copy-move-demo/archive.txt
Expected Terminal Signal
Both commands usually complete silently on success. Confirm with:
ls copy-move-demo
You should see report.txt and archive.txt (with backup.txt removed after move).
Why This Matters
Copy-before-move protects source material while you validate downstream steps. This is especially valuable in release prep and log curation pipelines.
Common Mistakes
- Moving directly without creating a recovery copy.
- Mixing source and destination order.
- Forgetting to inspect resulting filenames.
Practice Extension
Try the full loop:
mkdir -p copy-move-demo
printf '%s\n' '# Runbook' > copy-move-demo/runbook.md
cp copy-move-demo/runbook.md copy-move-demo/runbook.bak
mv copy-move-demo/runbook.bak copy-move-demo/runbook-archive.md
ls copy-move-demo
Repeat until source/destination ordering becomes instant and error-free.
References
These documentation links provide authoritative details for the commands used in this article.
Up Next
Practice file and directory cleanup patterns safely before using them in real workflows.