Use rm, rmdir, glob patterns, and understand why Linux has no Recycle Bin. Learn safe deletion practices that prevent catastrophic mistakes in production.
💡 Linux has no Recycle Bin.rm permanently deletes. There is no "undo". In a container or test environment this is fine — on a production server, one wrong rm -rf can be catastrophic.
Step 2: Deleting Directories
mkdir/tmp/empty_dirrmdir/tmp/empty_dir# works on empty directories onlyecho"Exit code: $?"# 0 = success
📸 Verified Output:
📸 Verified Output:
📸 Verified Output:
💡 rm -r is powerful — it deletes everything inside a directory tree. Always double-check the path before running it.
Step 3: Glob Patterns for Batch Deletion
📸 Verified Output:
📸 Verified Output:
💡 Always test your glob before deleting. Run ls /path/*.txt first, confirm it shows what you expect, then replace ls with rm. This habit prevents disasters.
Step 4: Interactive Deletion (-i flag)
📸 Verified Output:
💡 Some sysadmins alias rm='rm -i' in their .bashrc on servers. In scripts, use -f (force, no prompts). In interactive use, -i adds a safety net.
Step 5: Verbose Deletion (-v flag)
📸 Verified Output:
💡 -v prints each file as it's deleted. Useful when running rm in scripts so you have an audit trail of exactly what was removed.
Step 6: The Danger of rm -rf
📸 Verified Output:
💡 The infamous rm -rf / would delete your entire system. Modern Linux distributions add a --no-preserve-root safeguard that you must explicitly add to override. Never run commands with -rf without triple-checking the path.
Step 7: Securely Deleting Sensitive Files
📸 Verified Output:
💡 On SSDs, shred and dd overwrites are unreliable due to wear-leveling. True secure deletion on SSDs requires full-disk encryption (dm-crypt) so deleted files are unrecoverable by default.
# Delete all .txt files (config.cfg survives)
rm /tmp/glob_test/*.txt
ls /tmp/glob_test/
config.cfg
# -i asks before each deletion (type n to cancel, y to proceed)
touch /tmp/ask_before_delete.txt
rm -i /tmp/ask_before_delete.txt << 'EOF'
y
EOF
echo "File deleted: $(ls /tmp/ask_before_delete.txt 2>&1)"
rm: remove regular empty file '/tmp/ask_before_delete.txt'? File deleted: ls: cannot access '/tmp/ask_before_delete.txt': No such file or directory