Top 10 Essential Linux Commands: Hands-On Beginner's Guide
What You'll Learn
- Instantly know "Where am I?" and "What's here?" using
pwd/ls - Master file/directory operations (create, view, copy, move, delete)
- Troubleshoot common issues (No such file / Permission denied / overwrite accidents) on your own
Target audience: Beginners working with Ubuntu servers (or local PC)
Prerequisites: Contains dangerous operations (rm). Only run commands in the "practice directory"
Quick Summary (The Pattern)
1) pwd → 2) ls -la → 3) cd → 4) mkdir -p → 5) touch → 6) echo ... > file → 7) cat → 8) cp -i → 9) mv -i → 10) rm -i
Table of Contents
- First, Create a Safe Practice Environment
- pwd: Check Your Location (Prevent Getting Lost)
- ls: List Contents (Look First)
- cd: Navigate (The King of "No such")
- mkdir: Create Directories (-p is Your Safety Net)
- touch: Create Empty Files
- echo: Output Text
- cat: Display Contents
- cp: Copy (-i Prevents Accidents)
- mv: Move/Rename (-i Prevents Accidents)
- rm: Delete (Be Extra Careful)
- Common Troubleshooting
- Efficiency Tips
- Practice Exercise (10 min)
- Next Steps
First, Create a Safe Practice Environment (Don't Practice Elsewhere)
To prevent "I don't know where I'm working" accidents, run this first:
$ mkdir -p ~/pgym/basic-commands $ cd ~/pgym/basic-commands $ pwd $ ls -la
/home/user/pgym/basic-commands total 8 drwxr-xr-x 2 user user 4096 Dec 17 10:00 . drwxr-xr-x 3 user user 4096 Dec 17 10:00 ..
Key Point: Only practice within this directory. If lost, return to pwd and ls -la.
1) pwd: Check Your Location (Prevent Getting Lost)
Basic
$ pwd
/home/user/pgym/basic-commands
Common Issues → Recovery
- "I don't know where I'm working"
→ Recovery: Firstpwd, thenls -la. These two commands reveal 80% of the situation - Symbolic links may show different paths than actual location
→ Recovery: Learnpwd -P(actual path) later (not required now)
2) ls: List Contents (Look First)
Basic
$ ls
The Pattern for Real Work (Remember This)
$ ls -la
total 12 drwxr-xr-x 2 user user 4096 Dec 17 10:00 . drwxr-xr-x 3 user user 4096 Dec 17 10:00 .. -rw-r--r-- 1 user user 0 Dec 17 10:01 a.txt
What to Look For (Super Important)
- First character:
-(file) /d(directory) rwx: permissionsuser user: owner/group
Common Issues → Recovery
- Hidden files (
.envetc.) not visible
→ Recovery: Usels -aor always usels -la - "I don't understand permissions or owner"
→ Recovery: Usels -la(lsalone lacks info)
3) cd: Navigate (The King of "No such")
Basic
$ mkdir -p dir1 $ cd dir1 $ pwd
/home/user/pgym/basic-commands/dir1
Common Shortcuts
$ cd ~ # Go home $ cd .. # Go up one level $ cd - # Return to previous
Common Issues → Recovery (Must Know)
bash: cd: xxx: No such file or directory
- 99% caused by: typo or wrong location
- Recovery pattern:
pwd(check current location)ls -la(check available options)- Copy correct spelling and
cd
Directory names with spaces
- → Recovery: Use quotes like
cd "My Documents"
4) mkdir: Create Directories (-p is Your Safety Net)
Basic
$ mkdir my_project
Real Work Pattern (Creates Parents Too)
$ mkdir -p projects/web/frontend
Usually no output (silence means success).
Common Issues → Recovery
File exists: Same name already exists
→ Recovery: Check withls -la. Use a different namePermission denied: No permission in that location
→ Recovery: Work in~/(home directory)
5) touch: Create Empty Files (Content Doesn't Increase)
Basic
$ touch a.txt b.txt $ ls -la
-rw-r--r-- 1 user user 0 Dec 17 10:05 a.txt -rw-r--r-- 1 user user 0 Dec 17 10:05 b.txt
Common Issues → Recovery
- Touching existing file "creates" → actually updates timestamp
→ Recovery: As intended. Content unchanged (can be confusing)
6) echo: Output Text (> overwrites, >> appends)
Basic (Display)
$ echo "Hello Linux"
Hello Linux
Write to File (Overwrite / Append)
$ echo "first line" > memo.txt $ echo "second line" >> memo.txt $ cat memo.txt
first line second line
Common Issues → Recovery
- Used
>to overwrite (meant to append)
→ Recovery: Use>>next time. Useset -o noclobberto prevent overwrites, but beginners should just use>> Permission denied(can't write there)
→ Recovery: Check permissions withls -la→ move to~/
7) cat: Display Contents (Don't Use on Large Files)
Basic
$ cat memo.txt
With Line Numbers (Useful for Logs/Configs)
$ cat -n memo.txt
1 first line
2 second line
Common Issues → Recovery
- cat on large file - screen scrolls too fast
→ Recovery: Useless(not in this top 10, but essential for real work)
Example:less /var/log/syslog(pressqto exit) No such file or directory
→ Recovery: Check filename withls -la(often a typo)
8) cp: Copy (-i Prevents Accidents)
Basic (File Copy)
$ cp a.txt a-copy.txt $ ls -la
Real Work Pattern (Confirm Overwrite)
$ cp -i a.txt memo.txt
cp: overwrite 'memo.txt'?
Copy Directory (-r)
$ mkdir dir2 $ cp -r dir1 dir2/dir1-backup
Common Issues → Recovery
cp: cannot stat 'xxx': No such file or directory
→ Recovery pattern:pwd→ls -la→ fix path/spelling- Worried about overwrite accidents
→ Recovery: Always usecp -i
9) mv: Move/Rename (-i Prevents Accidents)
Basic (Rename)
$ mv a-copy.txt a2.txt $ ls -la
Basic (Move)
$ mkdir moved $ mv a2.txt moved/ $ ls -la moved
Real Work Pattern (Confirm Overwrite)
$ mv -i memo.txt moved/
Common Issues → Recovery
- "Moved it but can't find it"
→ Recovery:ls -la, thenfind . -name "memo.txt"(see find article) - Worried about overwrite
→ Recovery: Always usemv -i
10) rm: Delete (Be "Too Careful" Here)
Basic (Delete File)
$ rm a.txt
Real Work Pattern (With Confirmation: Start Here)
$ rm -i b.txt
rm: remove regular file 'b.txt'?
Common Issues → Recovery
rm: cannot remove 'dir1': Is a directory
→ Recovery: Directories needrm -r(dangerous - check contents withls -lafirst)Permission denied
→ Recovery: No permission. Don't blindly sudo. See Permission denied article- Wildcard accident (e.g.,
rm -rf *)
→ This is the king of accidents. Beginners should never userm -rf
Common Troubleshooting (Quick Diagnosis)
1) "No such file or directory" appeared
- First
pwd - Then
ls -la - If still failing: "wrong path", "spelling", or "case sensitivity"
2) "Permission denied" appeared
- First check "owner/permissions" with
ls -la - Don't blindly sudo (hides root cause)
- See Permission denied fix guide
Efficiency Tips (Quick Wins Only)
Tabcompletion: Type part of file/directory name and press TabCtrl + A(go to start) /Ctrl + E(go to end)historyandCtrl + R(search past commands)
Practice Exercise (10 min)
This exercise covers the essential pattern for real work (create → write → verify → organize).
$ cd ~/pgym/basic-commands $ mkdir -p my_profile $ cd my_profile $ touch profile.txt $ echo "name: your_name" > profile.txt $ echo "role: beginner" >> profile.txt $ cat -n profile.txt
Expected output:
1 name: your_name
2 role: beginner
Next Steps
Verification Environment
Commands in this article verified on Ubuntu 24.04 LTS / bash 5.2.
Master Basic Commands Through Practice
Once you've learned the "patterns" for these 10 commands, practice hands-on with Penguin Gym Linux exercises to solidify your skills.