Linux terminal – where file operations happen
Introduction to File Management
Managing files and folders is fundamental in Linux. While GUI tools exist, the terminal provides more power and flexibility. Let’s explore essential commands with practical examples.
1. Deleting Files & Folders (rm command)
Basic Syntax:
rm [options] filename
Key Options:
rm notes.txt
→ Deletes single filerm -i report.docx
→ Prompts before deletion (safer)rm *.tmp
→ Deletes all .tmp files in current directory
Deleting Folders:
rm -r Projects/
→ Deletes folder recursivelyrm -rf OldBackups/
→ Force-deletes without prompts (use carefully!)
⚠️ Danger Zone:
rm -rf /
→ NEVER RUN THIS! Destroys entire system
Always double-check paths before pressing Enter
2. Copying Files & Folders (cp command)
Basic Syntax:
cp [options] source destination
Common Use Cases:
cp document.txt ~/Documents/
→ Copies file to Documentscp -v image.jpg wallpaper.jpg
→ Copies with verbose outputcp *.png /media/usb/
→ Copies all PNGs to USB drive
Copying Folders:
cp -R Music/ /backup/
→ Recursive copy (-R flag)cp -a Photos/ VacationPhotos/
→ Archive mode (preserves permissions/timestamps)
3. Moving/Renaming Files & Folders (mv command)
Basic Syntax:
mv [options] source destination
Key Functions:
mv old_name.txt new_name.txt
→ Renames filemv report.pdf ~/Documents/
→ Moves filemv * /tmp/
→ Moves ALL files to /tmp directory
Moving Folders:
mv ProjectAlpha/ BetaProject/
→ Renames foldermv Downloads/movies/ /media/
→ Moves folder to new location
Visual Cheat Sheet
Common command syntax reference
Pro Tips for Beginners
-
Dry Run First:
Use-n
(no-clobber) withcp
/mv
to test:
cp -n file1 backup/
-
Undo Safety Net:
Installtrash-cli
:
trash-put file.txt
→ Moves to trash instead of permanent delete -
Tab Completion:
Type partial name + Tab to auto-complete paths -
Confirm Operations:
Always use-i
when learning:
alias cp='cp -i'
(add to ~/.bashrc)
Practice Scenario
# Create practice files
touch file{1..3}.txt
mkdir Backup
# Copy with confirmation
cp -i file1.txt Backup/
# Rename file
mv file2.txt data.txt
# Delete safely
rm -i file3.txt
Conclusion
Mastering rm
, cp
, and mv
unlocks efficient Linux file management. Remember:
✅ Always verify paths before deleting
✅ Use -i
for interactive confirmation
✅ Start with non-critical files to practice
When in doubt – double check!