0) How commands are written
command [options] [arguments]
# example:
ls -la /etc
- Use Tab to autocomplete, ↑/↓ to reuse history, Ctrl+C to stop a running command.
1) Navigation & paths
pwd # print current directory
ls # list files
ls -la # list all (incl. hidden) with details
cd /path/to/dir # change directory (absolute)
cd .. # go up one level
cd ~ # go to your home
Tips: Linux is case-sensitive. ~ means your home; . = current dir; .. = parent.
2) Creating & managing files/folders
mkdir lab # make a folder
mkdir -p proj/src # make nested folders
touch notes.txt # create empty file or update timestamp
cp a.txt b.txt # copy a → b
cp -r src/ backup/ # copy folder recursively
mv oldname.txt newname.txt # rename (or move)
mv file.txt dir/ # move into dir
rm file.txt # delete file
rm -r tmpdir/ # delete folder (recursive)
rm -ri tmpdir/ # safer: ask before each delete
Safety: avoid sudo rm -rf /. When learning, prefer rm -ri.
3) Viewing files
cat file.txt # print entire file
less file.txt # paged view (q to quit, /search)
head -n 20 file.txt # first 20 lines
tail -n 50 file.txt # last 50 lines
tail -f app.log # follow a growing log
nl file.txt # show with line numbers
4) Finding files & searching text
find . -name "*.py" # find by name
find /var/log -type f -size +100M # big log files
grep "ERROR" server.log # search text
grep -R "main(" src/ # search recursively
grep -n "todo" *.md # show line numbers
Pipeline example:
dmesg | grep -i usb | tail -n 20
5) Redirection & pipes (superpower)
ls -l > list.txt # write output to file (overwrite)
echo "hello" >> notes.txt # append
wc -l < notes.txt # feed file as input
cmd1 | cmd2 | cmd3 # pipe: output → input
somecmd | tee out.txt # see on screen AND save to file
cmd > all.log 2>&1 # combine stdout+stderr into file
6) Permissions & ownership (quick)
ls -l # view perms: -rwxr-x---
chmod u+x run.sh # add execute for owner
chmod 750 run.sh # u=rwx,g=rx,o=-
chown user:group file # change owner/group (needs sudo)
- r=4, w=2, x=1 → 7=rwx, 6=rw-, 5=r-x, 4=r--.
7) System & hardware info
whoami # your username
id # uid/gid and groups
uname -a # kernel/system
lsb_release -a # distro info (Ubuntu/Debian)
date # current date & time
uptime # how long the system is running
free -h # RAM usage
df -h # disk usage per mount
du -sh * # sizes of items in current dir
lsblk # disks/partitions
8) Processes & monitoring
ps aux # all processes
top # live monitor (q to quit)
htop # nicer top (sudo apt install htop)
pgrep firefox # find PIDs by name
kill 1234 # ask process 1234 to exit
kill -9 1234 # force kill (last resort)
9) Networking basics
ip a # show interfaces/IPs
ping -c 3 8.8.8.8 # test connectivity (3 pings)
curl -I https://example.com # HTTP headers
wget https://example.com/x # download a file
ss -tuna # open sockets (like netstat)
10) Package management (Ubuntu/Debian)
sudo apt update
sudo apt install tree git build-essential
sudo apt remove packagename
sudo apt upgrade
dpkg -l | less # list installed packages
(For Fedora/RHEL use dnf; for Arch use pacman.)
11) Compression & archives
# tarballs
tar -czf project.tar.gz project/ # create gzip tar
tar -xzf project.tar.gz # extract
# zip
zip -r project.zip project/ # zip folder
unzip project.zip # unzip
12) Users & groups (basics)
groups # your groups
passwd # change your password
# admin tasks (need sudo):
sudo adduser alice
sudo usermod -aG sudo alice
13) Shell quality-of-life
history # command history
!! # run previous command
!git # run last command starting with 'git'
echo $PATH # where the shell searches for programs
alias ll='ls -alF' # quick alias (put in ~/.bashrc)
source ~/.bashrc # reload config
Quoting rules:
- "double quotes" keep spaces but expand $vars
- 'single quotes' keep text literally (no expansion)
14) Text processing one-liners (handy!)
cat file.txt | sort | uniq -c | sort -nr | head
# -> frequency count of lines (top N)
grep -R "ERROR" logs | cut -d: -f1 | sort | uniq -c | sort -nr | head
# -> which files have most ERROR lines
15) Mini-lab (30–40 minutes, do it now)
# setup sandbox
mkdir -p ~/lab/cli101 && cd ~/lab/cli101
echo -e "apple\nbanana\napple\ncherry" > fruits.txt
echo "Line one" > notes.txt
echo "Line two" >> notes.txt
# practice viewing/search
nl notes.txt
grep -n "apple" fruits.txt
# practice find + pipes
printf "log1\nlog2\n" | xargs -I{} sh -c 'echo "ERROR on {}" >> {}.txt'
grep -R "ERROR" . | tee errors_all.txt
# disk & system checks
df -h
du -sh *
# permissions
echo -e '#!/usr/bin/env bash\necho "Hello $USER"' > hello.sh
chmod 755 hello.sh
./hello.sh
# archive
tar -czf lab_backup.tgz .
ls -lh lab_backup.tgz
Quick exam-ready bullets
- Navigation: pwd, ls -la, cd, mkdir, cp -r, mv, rm -ri
- Viewing: cat, less, head, tail -f, nl
- Search: grep -R, find
- Pipes/redirect: |, >, >>, 2>&1, tee
- Permissions: ls -l, chmod, (concept of user/group/others)
- System/Proc: uname -a, free -h, df -h, top, ps aux, kill
- Network: ip a, ping, curl, wget, ss -tuna
- Packages: sudo apt update && sudo apt install <pkg>
- Archives: tar -czf, tar -xzf, zip, unzip
Want these as a 2-page printable PDF or a slide deck for your class? I can format and share it.