The Terminal & Shell Basics
The terminal is the cockpit every later lab flies from. You type a command, the shell (usually Bash) runs it and prints the result. This lesson is about fluency, moving, reading, and combining commands without thinking, not writing scripts yet.
Run everything in the sandbox beside you as you read.
Navigating
Three commands do 90% of moving around:
pwd # print working directory , where am I?
ls # list files here (ls -l long, ls -a hidden)
cd /etc # change directory
Paths come in two flavours:
- Absolute , starts at root
/:/etc/ssh/sshd_config. - Relative , from where you are:
ssh/sshd_config(if you are in /etc).
Handy shortcuts: ~ is your home directory, .. is the parent, . is here.
cd /var/www/html # jump somewhere absolute
cd .. # up one level -> /var/www
cd ~ # back home
Reading files and manuals
cat notes.md # dump a whole file
less /etc/passwd # scroll a long file (q to quit) , 'more' is similar
head -n 5 /etc/passwd # first 5 lines tail -n 5 = last 5
man ls # the manual , your first stop for any command
man is the habit that separates beginners from the fluent: when unsure, read the manual instead of guessing.
Pipes: chain commands with |
A pipe sends the output of one command into the input of the next. This is the core idea of the Unix shell, small tools combined.
cat /etc/passwd | grep root # only lines containing 'root'
cat /etc/passwd | wc -l # count the lines (how many users?)
ps aux | grep nginx # is nginx running?
cat /etc/passwd | cut -d : -f 1 # just the usernames (field 1, ':' delimiter)
Read a pipeline left to right: produce text, then filter it, then count it.
Redirection: send output to a file
>writes output to a file, overwriting it.>>appends to the end instead.
echo "hello" > note.txt # create/overwrite note.txt
echo "second line" >> note.txt # add a line
cat note.txt # see both lines
Editing config files
On a real box you would open a config in an editor (nano /etc/ssh/sshd_config for beginners, vim for the fluent). Two things you will do constantly:
- Read a setting:
grep PermitRootLogin /etc/ssh/sshd_config - Append a setting:
echo "PasswordAuthentication no" >> sshd_config
(The sandbox can't open a full-screen editor, so practise reading with cat/grep and changing files with >>.)
Try it (terminal)
pwd, thencd /etc, thenls, thencd ~.cat /etc/passwd | grep root, filter with a pipe.cat /etc/passwd | wc -l, how many user accounts?echo "my first note" > note.txtthencat note.txt.man grep, skim the options.
Why this matters
Every lesson after this, Linux files, processes, privilege escalation, recon, assumes you can move around, read files, pipe, and redirect without looking it up. Get fluent here and the rest gets much easier.