Linux: The Thing Every Dev Should Know - Part 05

April 6, 2026

sudo (superuser-do) command

sudo stands for superuser do — it lets you run commands with admin (root) privileges.

Usage

sudo apt update
  • Executes command with elevated permissions

Usecases

  • Install packages
  • Modify system files
  • Manage services
  • have highest power or permissions of the system

Why

  • Protects your system from accidental changes
  • Grants controlled access to powerful operations

Careful

  • Can modify or break your system
  • Always know what you’re running

Pro tip :)

  • sudo is power with responsibility — use it intentionally, not casually.
  • Use sudo only when necessary — it runs commands as root.

df (disk-free) command

df stands for disk free — it shows available and used disk space on your system.

Usage

df
  • Displays disk usage for all mounted filesystems

Usecases

  1. Human-readable format:
df -hg
  1. Check specific path:
df -h /home

Why

  • Monitor disk usage
  • Avoid running out of storage
  • Useful in servers & deployments

Pro tip :)

  • Always use -h for readability — raw bytes aren’t practical.
  • Use df to quickly check your system’s storage health.

du (disk-usage) command

du stands for disk usage — it shows how much space files and directories are using.

Usage

du
  • Displays size of files/folders in current directory

Usecases

  1. Human-readable:
du -h
  1. Total size of a folder:
du -sh folder/
  1. Sort largest files:
du -h | sort -hr

Why

  • Find large files/folders
  • Clean up disk space
  • Debug storage issues

Pro tip :)

  • Use du -sh * to quickly see what’s taking space.
  • Use du to track what’s eating your disk.

df v/s du

  • df → Shows disk space available (filesystem level)
  • du → Shows space used by files/folders (directory level)

Lament example or real world

  • df = “How full is my disk?”
  • du = “What is filling my disk?”

vi / vim command

  • vi → basic text editor
  • vim → Vi Improved (more powerful version)

Used to create and edit files directly in terminal

Open a file

vim file.txt

Different modes

  1. Normal mode → navigate
  2. Insert mode → type text (i)
  3. Command mode → save/quit (:)

Commands most common ones

  • i → start typing
  • Esc → exit insert mode
  • :w → save
  • :q → quit
  • :wq → save & quit
  • :q! → quit without saving

Why

  • Works everywhere (servers, SSH, minimal systems)
  • Fast and keyboard-driven
  • Essential for dev & DevOps workflows

Pro tip :)

  • Vim feels hard at first, but once it clicks — it’s insanely fast.
  • Learn Vim once, use it everywhere.

head command

head is used to display the first few lines of a file (default: 10 lines).

Usage

head file.txt
  • shows first 10 lines

Usecases

  1. Show specific number of lines:
head -n 5 file.txt
  1. Use with pipes:
cat file.txt | head

Why

  • Quickly inspect large files
  • Useful for logs & debugging

Pro tip :)

  • Pair head with tail to explore files efficiently.
  • Use head to peek at the beginning of files instantly.

tail command

tail shows the last few lines of a file (default: 10 lines).

Usage

tail file.txt
  • Shows last 10 lines

Usecases

  1. Show specific lines:
tail -n 5 file.txt
  1. Live logs (real-time updates):
tail -f app.log

head & tail together

head -n 20 file.txt | tail -n 10
  • Gets lines 11–20

Why the combo

  • Quickly slice parts of large files
  • Useful for logs, debugging, data inspection

Pro tip :)

  • head trims from top, tail trims from bottom — together they isolate exactly what you need.
  • Use tail for the end, combine with head for precision.

diff command

diff is used to compare two files and show the differences between them.

Usage

diff file1.txt file2.txt
  • Shows what lines were added, removed, or changed

Common Usecases

  1. Side-by-side comparison:
diff -y file1.txt file2.txt
  1. Ignore whitespace:
diff -w file1.txt file2.txt

Why

  • Track changes in files
  • Debug differences
  • Core concept behind version control (like Git)

Pro tip :)

  • diff is the foundation of how tools like Git detect changes.
  • Use diff to instantly spot what changed.

locate command

locate is used to quickly search files by name using a pre-built database.

Usage

locate file.txt
  • Finds all paths matching file.txt

Usecases

  1. Case-insensitive search:
locate -i file.txt
  1. Limit results:
locate -n 5 file.txt

Uses a database (not real-time search) Update it with:

sudo updatedb

Why

  • Much faster than find
  • Great for quick lookups

Pro tip :)

  • locate is fast because it searches an index, not the filesystem.
  • Use locate for speed, find for accuracy.

find command

find is used to search files and directories in real-time based on name, type, size, etc.

Usage

find . -name "file.txt"
  • Searches current directory (.) for file.txt

Usecases

  1. Case-insensitive search:
find . -iname "file.txt"
  1. Find by type:
find . -type f # files find . -type d # directories
  1. Find and delete:
find . -name "*.log" -delete

Why is important

  • Real-time, accurate search
  • Extremely powerful with filters
  • Essential for automation & scripting

Pro tip :)

  • find is slower than locate, but always up-to-date and precise.
  • Use find when accuracy matters.
GitHub
LinkedIn
X