Day 04 — Linux Basic Commands for DevOps Engineers
🎯 Goal
Build strong command-line fundamentals to navigate systems, inspect files, and operate Linux servers confidently.
These are the commands you will use every single day in DevOps and backend engineering.
🧠 Mental Model
Linux CLI is your API to the OS.
Commands → Combined → Solve real problems
Each command:
- Does one thing well
- Can be combined with others
- Works on text streams
1️⃣ Navigation & Directory Management
pwd — Print Working Directory
pwdWhat it does:
Shows your current location in the filesystem.
Why it matters:
- Always know where you are before running commands
- Prevent accidental file deletion
ls — List Files
ls
ls -l
ls -lh
ls -aWhat it does:
Lists files and directories.
Options:
| Option | Meaning |
|---|---|
| -l | Detailed list (permissions, size, owner) |
| -h | Human-readable sizes |
| -a | Show hidden files |
Why it matters:
- Inspect directories
- Check permissions and file sizes
cd — Change Directory
cd /etc
cd ~
cd ..What it does:
Moves you between directories.
Why it matters:
- Navigate system structure quickly
mkdir — Create Directory
mkdir test
mkdir -p parent/childWhat it does:
Creates directories.
Why it matters:
- Create project structure
-pcreates nested directories safely
Delete Directories
rmdir test
rm -r test
rm -rf testWhat it does:
rmdir→ removes empty directoryrm -r→ recursive deleterm -rf→ force delete
⚠️ Dangerous command — use carefully.
2️⃣ File Creation & Manipulation
touch — Create File
touch file.txtWhat it does:
Creates empty file or updates timestamp.
cp — Copy Files
cp file.txt copy.txt
cp -r dir1 dir2What it does:
Copies files/directories.
Why it matters:
- Backup files
- Duplicate configs
mv — Move / Rename
mv file.txt new.txt
mv file.txt /tmp/What it does:
Moves or renames files.
3️⃣ Viewing File Content
cat — Display File
cat file.txtWhat it does:
Prints file content to terminal.
zcat — Read Compressed Files
zcat file.gzWhat it does:
Reads .gz files without extracting.
less / more
less file.txt
more file.txtWhat it does:
View large files page by page.
👉 less is preferred (scrollable).
head / tail
head file.txt
tail file.txt
tail -f logfile.logWhat it does:
head→ first linestail→ last linestail -f→ live log monitoring
4️⃣ Text Processing Commands
wc — Count
wc file.txt
wc -l file.txtWhat it does:
Counts lines, words, bytes.
cut — Extract Columns
cut -d ":" -f1 /etc/passwdWhat it does:
Extracts specific fields.
sort — Sort Data
sort file.txt
sort -n numbers.txtWhat it does:
Sorts lines alphabetically or numerically.
diff — Compare Files
diff file1.txt file2.txtWhat it does:
Shows differences between files.
tee — Output + Save
echo "hello" | tee file.txtWhat it does:
Writes output to file AND terminal.
5️⃣ Links (Important Concept)
Hard Link
ln file.txt hardlink.txtWhat it does:
Creates another reference to same file.
Soft Link (Symlink)
ln -s file.txt symlink.txtWhat it does:
Creates pointer to file.
6️⃣ System Utilities
clear
clearClears terminal screen.
7️⃣ Editing Files — vi
vi file.txtModes:
| Mode | Action |
|---|---|
| i | Insert |
| Esc | Exit insert |
| :w | Save |
| :q | Quit |
| :wq | Save + Quit |
🧪 Day-4 Lab
pwd
ls -l
cd /tmp
mkdir testdir
cd testdir
touch file1.txt
echo "hello world" > file1.txt
cp file1.txt file2.txt
mv file2.txt renamed.txt
cat file1.txt
less file1.txt
head file1.txt
tail file1.txt
wc file1.txt
cut -d " " -f1 file1.txt
sort file1.txt
ln file1.txt hardlink.txt
ln -s file1.txt symlink.txt
diff file1.txt renamed.txt
cd ..
rm -r testdir🧠 Key Takeaways
- CLI is your main interface
- Files & logs are core to debugging
- Commands are composable
- Small tools → powerful workflows
✅ Outcome
You can now:
- Navigate Linux systems confidently
- Manage files and directories
- Inspect file contents
- Perform basic data processing
- Understand links and editing
Next → Advanced Linux Commands 🚀