Mastering file and folder operations is essential for Linux beginners. Here’s a practical guide to fundamental commands with examples and visuals:
📁 1. pwd (Print Working Directory)
Shows your current folder path:
$ pwd
/home/user/documents
📂 2. ls (List Contents)
Lists files/folders in your current directory:
$ ls
file1.txt projects/ photos/
Common flags:
ls -l
: Detailed listls -a
: Show hidden files
🚪 3. cd (Change Directory)
Navigate between folders:
$ cd projects # Enter 'projects' folder
$ cd .. # Go back one level
$ cd ~ # Return to home directory
➕ 4. mkdir (Make Directory)
Create new folders:
$ mkdir new_folder
$ mkdir -p projects/code/python # Create nested directories
📄 5. touch (Create Files)
Create empty files:
$ touch notes.txt
$ touch file1.txt file2.txt # Multiple files
🧭 6. cp (Copy)
Copy files/folders:
$ cp file.txt backup/ # Copy to folder
$ cp -r old_dir/ new_dir/ # Copy directory recursively
🚚 7. mv (Move/Rename)
Move or rename items:
$ mv file.txt documents/ # Move to folder
$ mv oldname.txt newname.txt # Rename file
🗑️ 8. rm (Remove)
Delete files/folders (caution!):
$ rm unwanted.txt # Delete file
$ rm -r old_project/ # Delete folder recursively
Always double-check before running rm
!
👁️ 9. Viewing Files
cat
: Show full file content$ cat config.txt
less
: Scroll through large fileshead -n 5 file.txt
: Show first 5 linestail -n 5 file.txt
: Show last 5 lines
🔍 10. find (Locate Files)
Search for files:
$ find ~/ -name "*.jpg" # Find JPEGs in home directory
⚠️ Pro Tips
- Use
tab
for auto-completion - Add
--help
after commands for quick help (e.g.,ls --help
) - Avoid spaces in filenames (use underscores instead)
Ctrl+C
stops any running command
Practice safely: Create a practice/
folder to experiment without risking important files. Happy commanding! 🐧💻