Skip to content

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.

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.

Everything in Linux is a file or a directory. Paths use forward slashes (/). The root of the filesystem is /.

CommandWhat it doesExample
pwdPrint the current directorypwd
lsList files in the current directoryls -la (all files, detailed)
cdChange directorycd /var/log
cd ..Go up one directorycd ..
cd ~Go to your home directorycd ~
cd -Go to the previous directorycd -

Absolute paths start with / (e.g., /etc/apache2/apache2.conf). Relative paths start from your current directory (e.g., ./config.txt or ../other-dir/).

CommandWhat it doesExample
catPrint a file’s contentscat /etc/hostname
lessView a file with scrolling (press q to quit)less /var/log/syslog
head / tailShow the first/last linestail -20 /var/log/syslog
cpCopy a file or directorycp file.txt backup.txt
mvMove or rename a filemv old.txt new.txt
rmRemove a file (no undo)rm temp.txt
rm -rRemove a directory and its contentsrm -r old-dir/
mkdirCreate a directorymkdir -p logs/2026
touchCreate an empty file or update a timestamptouch notes.txt
CommandWhat it doesExample
grepSearch for a pattern in filesgrep "error" /var/log/syslog
grep -rSearch recursively in a directorygrep -r "DB_HOST" /var/www/
grep -iCase-insensitive searchgrep -i "warning" log.txt
findLocate files by name or attributesfind /etc -name "*.conf"
whichShow the path of a commandwhich python3

The shell’s real power is combining small commands. The pipe (|) sends one command’s output as input to another.

Terminal window
# Count how many lines contain "error" in the syslog
grep "error" /var/log/syslog | wc -l
# Show the 10 largest files in /var
du -ah /var | sort -rh | head -10
# Find which process is listening on port 80
ss -tlnp | grep :80

Redirection sends output to a file instead of the screen:

Terminal window
echo "hello" > file.txt # Write (overwrite) to file
echo "world" >> file.txt # Append to file
command 2> errors.log # Redirect errors only
command > out.log 2>&1 # Redirect both stdout and stderr

Every file has an owner, a group, and permissions for read (r), write (w), and execute (x).

Terminal window
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--)
CommandWhat it doesExample
chmodChange file permissionschmod +x script.sh
chmod 755Set specific permissions (owner rwx, group r-x, others r-x)chmod 755 script.sh
chownChange file ownersudo 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.

Terminal window
sudo apt update # Update package lists
sudo systemctl restart nginx # Restart a service
sudo vim /etc/hosts # Edit a system file

Use sudo only when necessary. Running everything as root is a security risk.

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.

Terminal window
nano /path/to/file.txt

nano shows keyboard shortcuts at the bottom of the screen. The ^ symbol means Ctrl.

ShortcutAction
Ctrl+OSave (write out)
Ctrl+XExit
Ctrl+KCut the current line
Ctrl+UPaste
Ctrl+WSearch
Ctrl+GHelp
Terminal window
vim /path/to/file.txt

vim 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/CommandModeAction
iNormalEnter Insert mode (start typing)
EscInsertReturn to Normal mode
:wNormalSave
:qNormalQuit
:wqNormalSave and quit
:q!NormalQuit without saving
ddNormalDelete the current line
uNormalUndo
/textNormalSearch for “text”
nNormalJump to next search match

Package managers install, update, and remove software. The package manager depends on your distribution.

DistributionManagerInstall example
Ubuntu/Debianaptsudo apt install nginx
Amazon Linux/RHELdnf / yumsudo dnf install nginx
macOSbrewbrew install wget

Always run sudo apt update (or equivalent) before installing packages to refresh the package list.

Environment variables store configuration that programs can read. They are written in ALL_CAPS by convention.

Terminal window
echo $HOME # Print your home directory
echo $PATH # Print the list of directories the shell searches for commands
export MY_VAR=42 # Set a variable for the current session

Variables 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.

Terminal window
# Connect to a remote server
ssh -i ~/Downloads/cs312-key.pem ubuntu@54.123.45.67
# Copy a file to a remote server
scp file.txt ubuntu@54.123.45.67:/home/ubuntu/
# Copy a file from a remote server
scp ubuntu@54.123.45.67:/var/log/syslog ./syslog-copy.txt

If you get a “permission denied” error on your key file, fix its permissions:

Terminal window
chmod 400 ~/Downloads/cs312-key.pem

When you encounter an unfamiliar command, these are the fastest ways to learn what it does:

Terminal window
man ls # Open the manual page for "ls" (press q to quit)
ls --help # Print a brief help summary
tldr 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.