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

pwd

What 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 -a

What it does:
Lists files and directories.

Options:

OptionMeaning
-lDetailed list (permissions, size, owner)
-hHuman-readable sizes
-aShow 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/child

What it does:
Creates directories.

Why it matters:

  • Create project structure
  • -p creates nested directories safely

Delete Directories

rmdir test
rm -r test
rm -rf test

What it does:

  • rmdir → removes empty directory
  • rm -r → recursive delete
  • rm -rf → force delete

⚠️ Dangerous command — use carefully.


2️⃣ File Creation & Manipulation

touch — Create File

touch file.txt

What it does:
Creates empty file or updates timestamp.


cp — Copy Files

cp file.txt copy.txt
cp -r dir1 dir2

What 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.txt

What it does:
Prints file content to terminal.


zcat — Read Compressed Files

zcat file.gz

What it does:
Reads .gz files without extracting.


less / more

less file.txt
more file.txt

What it does:
View large files page by page.

👉 less is preferred (scrollable).


head / tail

head file.txt
tail file.txt
tail -f logfile.log

What it does:

  • head → first lines
  • tail → last lines
  • tail -f → live log monitoring

4️⃣ Text Processing Commands

wc — Count

wc file.txt
wc -l file.txt

What it does:
Counts lines, words, bytes.


cut — Extract Columns

cut -d ":" -f1 /etc/passwd

What it does:
Extracts specific fields.


sort — Sort Data

sort file.txt
sort -n numbers.txt

What it does:
Sorts lines alphabetically or numerically.


diff — Compare Files

diff file1.txt file2.txt

What it does:
Shows differences between files.


tee — Output + Save

echo "hello" | tee file.txt

What it does:
Writes output to file AND terminal.


5️⃣ Links (Important Concept)

ln file.txt hardlink.txt

What it does:
Creates another reference to same file.


ln -s file.txt symlink.txt

What it does:
Creates pointer to file.


6️⃣ System Utilities

clear

clear

Clears terminal screen.


7️⃣ Editing Files — vi

vi file.txt

Modes:

ModeAction
iInsert
EscExit insert
:wSave
:qQuit
:wqSave + 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 🚀