The Terminal, Shell, and Text Editors
If you have never used a terminal before, this page will get you oriented. If you have, use it as a quick reference. This is not a comprehensive guide; it covers enough to be productive in this course.
Terminal vs. Shell
Section titled “Terminal vs. Shell”A terminal (or terminal emulator) is the window you type commands into. A shell is the program running inside that window that interprets your commands and executes them.
Common shells:
- bash (Bourne Again Shell): the default on most Linux servers and older macOS versions.
- zsh (Z Shell): the default on modern macOS. Nearly identical to bash for basic usage.
When you open Terminal on macOS or a WSL window on Windows, you are running a shell inside a terminal. The prompt (something like ubuntu@ip-172-31-0-5:~$) tells you who you are, where you are, and that the shell is ready for input.
Navigating the Filesystem
Section titled “Navigating the Filesystem”Everything in Linux is a file or a directory. Paths use forward slashes (/). The root of the filesystem is /.
| Command | What it does | Example |
|---|---|---|
pwd | Print the current directory | pwd |
ls | List files in the current directory | ls -la (all files, detailed) |
cd | Change directory | cd /var/log |
cd .. | Go up one directory | cd .. |
cd ~ | Go to your home directory | cd ~ |
cd - | Go to the previous directory | cd - |
Absolute paths start with / (e.g., /etc/apache2/apache2.conf). Relative paths start from your current directory (e.g., ./config.txt or ../other-dir/).
Working with Files
Section titled “Working with Files”| Command | What it does | Example |
|---|---|---|
cat | Print a file’s contents | cat /etc/hostname |
less | View a file with scrolling (press q to quit) | less /var/log/syslog |
head / tail | Show the first/last lines | tail -20 /var/log/syslog |
cp | Copy a file or directory | cp file.txt backup.txt |
mv | Move or rename a file | mv old.txt new.txt |
rm | Remove a file (no undo) | rm temp.txt |
rm -r | Remove a directory and its contents | rm -r old-dir/ |
mkdir | Create a directory | mkdir -p logs/2026 |
touch | Create an empty file or update a timestamp | touch notes.txt |
Searching
Section titled “Searching”| Command | What it does | Example |
|---|---|---|
grep | Search for a pattern in files | grep "error" /var/log/syslog |
grep -r | Search recursively in a directory | grep -r "DB_HOST" /var/www/ |
grep -i | Case-insensitive search | grep -i "warning" log.txt |
find | Locate files by name or attributes | find /etc -name "*.conf" |
which | Show the path of a command | which python3 |
Pipes and Redirection
Section titled “Pipes and Redirection”The shell’s real power is combining small commands. The pipe (|) sends one command’s output as input to another.
# Count how many lines contain "error" in the sysloggrep "error" /var/log/syslog | wc -l
# Show the 10 largest files in /vardu -ah /var | sort -rh | head -10
# Find which process is listening on port 80ss -tlnp | grep :80Redirection sends output to a file instead of the screen:
echo "hello" > file.txt # Write (overwrite) to fileecho "world" >> file.txt # Append to filecommand 2> errors.log # Redirect errors onlycommand > out.log 2>&1 # Redirect both stdout and stderrFile Permissions
Section titled “File Permissions”Every file has an owner, a group, and permissions for read (r), write (w), and execute (x).
ls -l script.sh# -rwxr-xr-- 1 ubuntu www-data 512 Mar 15 script.sh# ^^^ owner permissions (rwx)# ^^^ group permissions (r-x)# ^^^ others permissions (r--)| Command | What it does | Example |
|---|---|---|
chmod | Change file permissions | chmod +x script.sh |
chmod 755 | Set specific permissions (owner rwx, group r-x, others r-x) | chmod 755 script.sh |
chown | Change file owner | sudo chown www-data:www-data index.html |
The numeric form (like 755) encodes permissions as three digits: owner, group, others. Each digit is the sum of read (4), write (2), and execute (1). So 755 means rwxr-xr-x.
sudo runs a command as the superuser (root). Most system administration tasks require it.
sudo apt update # Update package listssudo systemctl restart nginx # Restart a servicesudo vim /etc/hosts # Edit a system fileUse sudo only when necessary. Running everything as root is a security risk.
Text Editors
Section titled “Text Editors”You will need to edit files on remote servers where there is no graphical interface. Two terminal editors are available on virtually every Linux system.
nano (beginner-friendly)
Section titled “nano (beginner-friendly)”nano /path/to/file.txtnano shows keyboard shortcuts at the bottom of the screen. The ^ symbol means Ctrl.
| Shortcut | Action |
|---|---|
Ctrl+O | Save (write out) |
Ctrl+X | Exit |
Ctrl+K | Cut the current line |
Ctrl+U | Paste |
Ctrl+W | Search |
Ctrl+G | Help |
vim (powerful but has a learning curve)
Section titled “vim (powerful but has a learning curve)”vim /path/to/file.txtvim has modes. You start in Normal mode (for navigation and commands). Press i to enter Insert mode (for typing text). Press Esc to return to Normal mode.
| Key/Command | Mode | Action |
|---|---|---|
i | Normal | Enter Insert mode (start typing) |
Esc | Insert | Return to Normal mode |
:w | Normal | Save |
:q | Normal | Quit |
:wq | Normal | Save and quit |
:q! | Normal | Quit without saving |
dd | Normal | Delete the current line |
u | Normal | Undo |
/text | Normal | Search for “text” |
n | Normal | Jump to next search match |
Package Managers
Section titled “Package Managers”Package managers install, update, and remove software. The package manager depends on your distribution.
| Distribution | Manager | Install example |
|---|---|---|
| Ubuntu/Debian | apt | sudo apt install nginx |
| Amazon Linux/RHEL | dnf / yum | sudo dnf install nginx |
| macOS | brew | brew install wget |
Always run sudo apt update (or equivalent) before installing packages to refresh the package list.
Environment Variables
Section titled “Environment Variables”Environment variables store configuration that programs can read. They are written in ALL_CAPS by convention.
echo $HOME # Print your home directoryecho $PATH # Print the list of directories the shell searches for commandsexport MY_VAR=42 # Set a variable for the current sessionVariables set with export last only until you close the terminal. To make them permanent, add the export line to your shell configuration file (~/.bashrc for bash, ~/.zshrc for zsh).
SSH (Secure Shell) connects you to a remote machine over an encrypted channel. You will use it constantly in this course.
# Connect to a remote serverssh -i ~/Downloads/cs312-key.pem ubuntu@54.123.45.67
# Copy a file to a remote serverscp file.txt ubuntu@54.123.45.67:/home/ubuntu/
# Copy a file from a remote serverscp ubuntu@54.123.45.67:/var/log/syslog ./syslog-copy.txtIf you get a “permission denied” error on your key file, fix its permissions:
chmod 400 ~/Downloads/cs312-key.pemGetting Help
Section titled “Getting Help”When you encounter an unfamiliar command, these are the fastest ways to learn what it does:
man ls # Open the manual page for "ls" (press q to quit)ls --help # Print a brief help summarytldr tar # Community-maintained cheat sheets (install with "brew install tldr" or "sudo apt install tldr")Reading manual pages (man) is a core skill. The format is dense at first but becomes natural with practice.