█
LastWrite
  • > Curriculum
  • > Pricing
  • > For Educators
  • > About
  • > Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
LastWrite

Structured computer science lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 LastWrite. All rights reserved.
Curriculum/DevOps and Infrastructure/Linux and the Command Line/Essential Commands
40 minBeginner

Essential Commands

After this lesson, you will be able to: Use the essential file and text commands (ls, cp, mv, rm, mkdir, find, grep, cat, less, tail, head, wc, sort, uniq) plus pipes and redirection.

These are the commands you'll type thousands of times. Pipes + redirection are what turn them from a list into a programming language.

Prerequisites:The Linux Filesystem

File operations

Each command has a man page (`man cp`) with every flag.

tsx
cp src.txt dest.txt # copy
cp -r src/ dest/ # copy directory recursively
mv old new # move or rename
rm file.txt # remove (no undo)
rm -rf dir/ # remove directory recursively (DANGER)
mkdir new-dir # create directory
mkdir -p a/b/c # create with parents
touch file.txt # create empty file or update mtime

Searching: find vs grep

find searches FILES BY METADATA; grep searches FILE CONTENTS.

tsx
# find files by name
find . -name '*.log'
find /var/log -name '*.gz' -mtime -7 # modified within last 7 days
find / -size +100M 2>/dev/null # files over 100MB (silence permission errors)
# grep file contents
grep -r 'TODO' src/ # recursive
grep -n 'error' app.log # show line numbers
grep -v 'DEBUG' app.log # invert (lines NOT containing)
grep -i 'warning' app.log # case-insensitive
grep -A 5 -B 2 'panic' app.log # 2 lines before, 5 after

Reading files: cat, less, head, tail

Pick the right tool for the file size and access pattern.

tsx
cat file.txt # dump whole file (small files only)
less file.txt # pager, scroll, search with /, quit with q
head -n 20 file.txt # first 20 lines
tail -n 20 file.txt # last 20 lines
tail -f app.log # FOLLOW: print new lines as they arrive (logs!)
tail -n 100 -f app.log # show last 100, then follow

Pipes, redirection, and the unix philosophy

This is where the shell becomes a real programming language.

tsx
# > redirects stdout to a file (overwrites)
ls > files.txt
# >> appends
ls >> files.txt
# < reads from a file as stdin
wc -l < files.txt
# 2> redirects stderr
command 2> errors.log
# &> redirects both stdout and stderr
command &> output.log
# /dev/null discards
command > /dev/null 2>&1
# | pipes stdout of one command into stdin of another
cat app.log | grep ERROR | wc -l
# count unique IPs in nginx access log
cat access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head
# kill all node processes
ps aux | grep node | awk '{print $2}' | xargs kill

Common mistakes only experienced users avoid

`rm -rf /` (or `rm -rf $UNSET_VAR/`), irreversible disaster. Modern rm refuses `/`, but `rm -rf $VAR/` where $VAR is empty deletes everything from `/`. Always quote and check. `cat huge.log` instead of `tail -f`. Eats memory; freezes the terminal. Forgetting `> /dev/null 2>&1` to fully silence. Using `grep -r` on `node_modules`. Add `--exclude-dir=node_modules` or use `rg` (ripgrep) which respects .gitignore by default. `mv` between filesystems is actually copy + delete, not atomic. Matters for backups.

Quick Check

What does this pipeline do? `cat /var/log/auth.log | grep 'Failed password' | awk '{print $11}' | sort | uniq -c | sort -rn | head`

Pick the cleanest description.

Sign in and purchase access to unlock this lesson.

Sign in to purchase
←The Linux Filesystem
Back to Linux and the Command Line
File Permissions→