•Updated•Arnošt Havelka
Bash Manipulation: Cleanup Rehearsal
Practice file and directory cleanup patterns safely before using them in real workflows.
Start Interactive LessonCleanup commands should be deliberate, not impulsive. This rehearsal focuses on removing known files and then removing an empty directory with separate commands.
Commands to Practice
mkdir -p cleanup-demo/scratch
touch cleanup-demo/temp1.txt cleanup-demo/temp2.txt
rm cleanup-demo/temp1.txt cleanup-demo/temp2.txt
rmdir cleanup-demo/scratch cleanup-demo
Expected Terminal Signal
Successful removals are silent. Verify state using:
test ! -e cleanup-demo && echo 'cleanup-demo removed'
The removed files and directory should no longer appear.
Why This Matters
Deletion is irreversible in many contexts. Building a verify-first habit before and after cleanup operations prevents avoidable outages.
Common Mistakes
- Running
rmwith broad patterns before listing targets. - Using directory removal commands on non-empty directories.
- Treating silent output as optional to verify.
Practice Extension
Create a disposable target, then remove it:
touch a.tmp b.tmp
rm a.tmp b.tmp
This controlled repetition builds precision and confidence for larger cleanup tasks.
References
These documentation links provide authoritative details for the commands used in this article.