T02: Terminal Basics

Buttons are for tourists. The terminal is the direct line to the machine - a text prompt where you tell the computer exactly what to do. It feels intimidating for about a week, then feels like a superpower for the rest of your career. You stop clicking through dialogs and start composing commands.

Where Am I? Moving Around

Your shell is always sitting in some folder, called the working directory. Three commands form the navigation basics: where am I, what is here, go somewhere.

pwd                    # print working directory
ls                     # list what is in this folder
ls -la                 # long format, include hidden files
cd Documents           # move into a subfolder
cd ..                  # move up one level
cd                     # go home (shorthand for ~)
cd /                   # jump to the filesystem root

Paths come in two flavors. An absolute path starts from the root: /home/alice/projects. A relative path starts from wherever you are now: ../notes. The special shortcuts . (here), .. (parent), and ~ (your home folder) show up everywhere.

Creating, Copying, Removing

Files and folders are text in, bytes out. Keep verbs short.

mkdir my-project              # make a folder
mkdir -p a/b/c                # make nested folders at once
touch notes.md                # create an empty file
cp notes.md backup.md         # copy file
cp -r my-project archive      # copy folder recursively
mv old.md new.md              # rename (or move)
rm notes.md                   # delete file (no recycle bin!)
rm -rf build/                 # delete folder and everything inside
cat notes.md                  # print file to screen
less log.txt                  # scroll through a large file (q to quit)

Warning: there is no trash can. rm is final. Before using rm -rf, always run ls first to verify the target.

Reading the Manual

Every command ships with its own manual. When you forget a flag, ask.

man ls                 # full manual page (q to quit)
ls --help              # quick summary (most modern commands)
which python           # show where a command lives on disk

The PATH: Why Commands Just Work

When you type git, the shell does not know where the git program lives. It walks a list of folders stored in the PATH environment variable and runs the first git it finds. This is why installing tools sometimes needs a PATH update.

echo $PATH                              # see the search list
# /usr/local/bin:/usr/bin:/bin:...
export PATH="$HOME/.local/bin:$PATH"    # add your own folder first
flowchart TD User[You type: git status] Shell[Shell reads PATH] P1["/usr/local/bin/git"] P2["/usr/bin/"] P3["..."] Run[Run the found program] User --> Shell Shell --> P1 Shell --> P2 Shell --> P3 P1 -->|first match wins| Run

Speed Tricks

The shell rewards muscle memory. Four habits that pay back every day:

Key Takeaways

  • pwd, ls, cd are your navigation basics. Paths are absolute (start with /) or relative (start from here)
  • mkdir, touch, cp, mv, rm manage files and folders. rm is permanent - there is no trash can
  • man and --help are always there when you forget a flag. Use them before Google
  • PATH is the search list the shell uses to find commands. Know how to inspect and extend it
  • Tab completion, Ctrl+R history search, and Ctrl+C to cancel are the muscle memory that separate beginners from pros