The terminal is a text-based interface that lets you communicate directly with your computer by typing commands. Instead of clicking icons and navigating menus, you type instructions and the computer executes them. The terminal is also called the command line, shell, or console — these terms are often used interchangeably, though they have subtle distinctions.
For most everyday tasks, a graphical interface is fine. But as a developer, the terminal becomes essential. Git, Node.js, npm, package managers, and deployment tools are all primarily operated through the command line. Understanding the terminal is not optional — it is a foundational skill that everything else in software development builds on.
The Terminal, the Shell, and the Command Line
These three terms are related but distinct:
| Term | What It Refers To |
|---|---|
| Terminal | The application window where you type commands. Examples: Terminal on macOS, Windows Terminal, GNOME Terminal on Linux. |
| Shell | The program running inside the terminal that interprets your commands. Examples: Bash, Zsh, Fish. |
| Command Line | The general concept of interacting with a computer through text commands rather than a graphical interface. |
On macOS, the default shell is Zsh. On most Linux distributions it is Bash. On Windows, the native shell is PowerShell or Command Prompt, but most developers install Git Bash or use the Windows Subsystem for Linux (WSL) to get a Unix-like environment. The commands in this topic follow Unix conventions (macOS and Linux), which are the standard in web development.
Why Developers Use the Terminal
- Speed — many tasks are faster to type than to click through menus.
- Power — the terminal gives you access to tools and capabilities that have no graphical equivalent.
- Automation — commands can be chained, scripted, and scheduled to run automatically.
- Industry standard — Git, Node.js, npm, deployment pipelines, and cloud platforms are all operated primarily through the command line.
- Remote access — servers have no graphical interface. SSH-ing into a server and working through the terminal is how server management works.
Anatomy of a Command
Every command follows a basic structure:
command [options] [arguments]
- Command — the program or tool you want to run (e.g.
ls,git,node). - Options (also called flags) — modifiers that change how the command behaves. They are prefixed with
-(short form) or--(long form). - Arguments — the input the command acts on, such as a file name or a path.
Example:
ls -la /home/wariz
ls— the command (list directory contents).-la— two flags combined:-l(long format) and-a(show hidden files)./home/wariz— the argument (the directory to list).
Navigating the File System
The file system is organised as a tree of directories (folders). At the top is the root directory (/ on Unix systems). Everything else lives inside it.
pwd — Print Working Directory
Shows you where you currently are in the file system.
pwd
# Output: /home/wariz/projects
ls — List Directory Contents
Lists the files and folders in the current directory.
ls # Basic list
ls -l # Long format (shows permissions, size, date)
ls -a # Includes hidden files (files starting with .)
ls -la # Long format + hidden files combined
ls /some/path # List a specific directory
cd — Change Directory
Moves you into a different directory.
cd projects # Move into the projects folder
cd .. # Move one level up (parent directory)
cd ../.. # Move two levels up
cd ~ # Move to your home directory
cd / # Move to the root directory
cd - # Go back to the previous directory
Understanding Paths
| Path Type | Description | Example |
|---|---|---|
| Absolute path | Starts from the root /. Works from anywhere. | /home/wariz/projects/app |
| Relative path | Relative to your current location. | ./projects/app or ../app |
. means the current directory. .. means the parent directory.
Working with Files and Folders
mkdir — Make Directory
Creates a new folder.
mkdir my-project # Create a single folder
mkdir -p projects/app/src # Create nested folders in one command
The -p flag means "create parent directories as needed" — without it, the command fails if the parent doesn't exist.
touch — Create a File
Creates a new empty file, or updates the timestamp of an existing one.
touch index.html
touch README.md
cp — Copy
Copies a file or folder.
cp file.txt copy.txt # Copy a file
cp -r my-folder my-folder-backup # Copy a folder (requires -r for recursive)
mv — Move or Rename
Moves a file to a new location, or renames it.
mv old-name.txt new-name.txt # Rename a file
mv file.txt /home/wariz/documents # Move a file to a different directory
rm — Remove
Deletes files or folders. There is no undo or trash — deleted files are gone permanently.
rm file.txt # Delete a file
rm -r my-folder # Delete a folder and all its contents
rm -rf my-folder # Force delete without confirmation prompts
The -f flag suppresses confirmation. Use rm -rf carefully — it is one of the most destructive commands in the terminal.
Reading File Contents
cat — Concatenate and Print
Prints the full contents of a file to the terminal. Best for short files.
cat README.md
cat package.json
less — Paginated View
Opens a file in a scrollable viewer. Useful for long files.
less README.md
Inside less:
- Arrow keys or
j/kto scroll. qto quit./searchtermto search.
head and tail
Print the first or last lines of a file.
head -n 20 file.txt # First 20 lines
tail -n 20 file.txt # Last 20 lines
tail -f log.txt # Follow a file in real time (useful for logs)
Useful Everyday Commands
clear — Clear the Terminal Screen
clear
Keyboard shortcut: Ctrl + L
echo — Print Text
Prints a string to the terminal. Commonly used in scripts or to check variable values.
echo "Hello, World!"
echo $HOME # Print the value of an environment variable
man — Manual Pages
Opens the manual page for a command — a built-in reference guide.
man ls
man git
Press q to exit.
which — Find a Command's Location
Shows where a program is installed.
which node # Output: /usr/local/bin/node
which git # Output: /usr/bin/git
history — Command History
Lists previously run commands. You can also press the Up arrow to cycle through recent commands.
history
Flags and Options
Flags modify the behaviour of a command. They come in two forms:
| Form | Example | Notes |
|---|---|---|
| Short | -a, -l, -r | Single dash, single letter. Can be combined: -la |
| Long | --all, --recursive | Double dash, full word. Cannot be combined. |
Short flags can be chained together: ls -la is the same as ls -l -a.
Piping and Redirection
Piping (|)
The pipe operator sends the output of one command as the input to another. This is how you chain commands together.
ls -la | less # Pipe ls output into less for scrolling
cat file.txt | grep "error" # Search file contents for the word "error"
grep — Search Text
Searches for a pattern inside a file or piped input.
grep "TODO" app.js # Find all lines containing "TODO" in app.js
grep -r "console.log" ./src # Search recursively in a folder
Output Redirection (> and >>)
Sends command output to a file instead of the terminal.
ls > file-list.txt # Write output to a file (overwrites)
ls >> file-list.txt # Append output to a file (does not overwrite)
Environment Variables
Environment variables are key-value pairs stored in the shell that programs can read. They are commonly used to store configuration, paths, and secrets.
echo $PATH # Print the PATH variable (directories the shell searches for commands)
echo $HOME # Print the home directory path
echo $USER # Print the current username
Setting a temporary variable (only lasts for the current session):
export MY_VAR="hello"
echo $MY_VAR # Output: hello
Running Programs and Scripts
Running a Node.js File
node app.js
Running npm Commands
npm install # Install dependencies
npm run dev # Run the dev script defined in package.json
npm run build # Run the build script
Running a Shell Script
bash script.sh # Run a shell script with bash
./script.sh # Run a script directly (must be executable)
Keyboard Shortcuts
These shortcuts work in most Unix terminals and save significant time:
| Shortcut | Action |
|---|---|
Ctrl + C | Cancel the currently running command |
Ctrl + Z | Suspend the current process |
Ctrl + L | Clear the screen |
Ctrl + A | Move cursor to the beginning of the line |
Ctrl + E | Move cursor to the end of the line |
Tab | Autocomplete a file name or command |
Tab Tab | Show all possible completions |
↑ / ↓ | Cycle through command history |
How the Terminal Connects to Development Tools
Understanding the terminal unlocks every major tool in a developer's workflow:
| Tool | How the Terminal Is Used |
|---|---|
| Git | All Git operations — committing, branching, pushing, pulling — are run in the terminal. |
| Node.js | Running JavaScript files outside the browser, starting servers, running scripts. |
| npm / yarn | Installing packages, running project scripts, managing dependencies. |
| Vite / Next.js | Starting development servers, running builds, scaffolding projects. |
| SSH | Connecting to remote servers for deployment and server management. |
| Docker | Building and running containers from the command line. |
Every subject on this platform — Git, Node.js, Express.js, Next.js — is operated primarily through the terminal. Fluency here compounds across everything else you learn.