learn/phase-2/p2-w6/lesson 01
Milestone 6 · lesson 1

The Terminal & Shell Basics

Hands-on: live every command in the sandbox terminal. Practical fluency, not scripting yet.
Lab: First Shell

Find the flag hidden in your home directory.

What you'll learn

  • Navigate the filesystem with pwd, ls and cd, and read paths (absolute, relative, ~, .., .).
  • Read files and manuals with cat, less and man.
  • Combine commands with pipes (|) and save output with redirection (> and >>).
  • Reach the daily terminal fluency every later lab assumes.

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)

  1. pwd, then cd /etc, then ls, then cd ~.
  2. cat /etc/passwd | grep root , filter with a pipe.
  3. cat /etc/passwd | wc -l , how many user accounts?
  4. echo "my first note" > note.txt then cat note.txt.
  5. 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.

Check your understanding

6 questions

Type an answer and press Check. Grading is keyword-based and forgiving, so short answers are fine.

  1. 1

    Write the command that prints your current working directory.

  2. 2

    You are in /home/learner. Write the command to move into the /etc directory.

  3. 3

    Using a pipe, write a command that shows only the lines of /etc/passwd that contain root.

  4. 4

    Write a command that saves the text hello into a file note.txt, overwriting it.

  5. 5

    Which command opens the manual page for grep?

  6. 6

    To ADD a line to a file without erasing what's there, do you use a single > or a double operator?