File Management Commands
Create, copy, move, rename, and delete files and folders from the terminal.
What You'll Learn
- touch and mkdir — creating files and directories
- cp — copying files and directories
- mv — moving and renaming
- rm — deleting safely (and dangerously)
Creating Files and Directories
📦 Real-World Analogy: touch is like placing an empty box on a shelf. mkdir is building a new shelf. mkdir -p is building an entire shelving unit with sub-shelves all at once.
# Create files $ touch README.md # single file $ touch index.html style.css # multiple files # Create directories $ mkdir components # single directory $ mkdir -p src/components/ui # nested directories
Viewing File Contents
$ cat file.txt # Print entire file $ head -20 file.txt # First 20 lines $ tail -20 file.txt # Last 20 lines $ tail -f server.log # Follow updates in real-time $ less file.txt # Scrollable viewer (q to quit) $ wc -l file.txt # Count lines
Creating Files
Practice creating files and directories.
// Creating Files & Directories — simulated
console.log("=== touch — Create Empty Files ===");
console.log("$ touch index.html");
console.log("$ touch style.css app.js");
console.log("$ touch src/components/Header.tsx");
console.log(" → Creates files (or updates timestamp if they exist)");
console.log();
console.log("=== mkdir — Create Directories ===");
console.log("$ mkdir projects");
console.log("$ mkdir -p src/components/ui");
console.log(" → -p creates parent directories as needed");
con
...Copy, Move, and Delete
# Copy $ cp source.txt destination.txt # Copy file $ cp -r project/ project-backup/ # Copy directory (-r required!) # Move / Rename $ mv old-name.txt new-name.txt # Rename $ mv file.txt ~/Documents/ # Move to another directory # Delete $ rm unwanted-file.txt # Delete file (PERMANENT!) $ rm -r old-project/ # Delete directory + contents $ rm -ri folder/ # Interactive (asks first)
⚠️ DANGER: rm Is Permanent!
Unlike dragging to the trash, rm permanently deletes files with no recovery. Never run rm -rf / or rm -rf * without triple-checking. Use rm -i for interactive confirmation when deleting important files.
💡 Pro Tip
Use wildcards (globs) to work with multiple files: rm *.tmp deletes all .tmp files, cp src/*.js dist/ copies all JS files. Always ls *.pattern first to verify what matches before deleting!
Copy, Move, Delete
Practice file management commands and wildcards.
// Copy, Move, Rename, Delete — simulated
console.log("=== cp — Copy ===");
console.log("$ cp file.txt backup.txt");
console.log(" → Copy a file");
console.log();
console.log("$ cp -r src/ src-backup/");
console.log(" → Copy a directory recursively (-r is required!)");
console.log();
console.log("$ cp *.js scripts/");
console.log(" → Copy all .js files into scripts/");
console.log();
console.log("=== mv — Move / Rename ===");
console.log("$ mv old-name.txt new-name.txt");
console.log(" → Re
...📋 Quick Reference
| Command | Description |
|---|---|
| touch file | Create empty file |
| mkdir -p dir | Create nested directories |
| cp -r src dst | Copy file/directory |
| mv old new | Move or rename |
| rm -ri dir | Delete interactively |
| cat / less | View file contents |
🎉 Lesson Complete!
You can now create, copy, move, and delete files with confidence. Next: text processing with grep, sed, and awk — the power tools of Unix.
Sign up for free to track which lessons you've completed and get learning reminders.