Skip to content

Command Line Basics

Learn the terminal: navigating directories, running commands, piping output, and why developers live in the shell.

What you'll learn

  • What the command line (terminal) is and why developers use it
  • Essential commands: ls, cd, pwd, mkdir, rm, cat
  • How to navigate the filesystem from the terminal
  • Piping and redirecting output between commands
  • How command-line skills accelerate development workflow

Concept

Command Line Basics

The command line (also called the terminal, shell, or console) is a text-based interface for interacting with your computer. Instead of clicking icons and menus, you type commands and press Enter. For developers, the command line is the primary workspace — it is faster, more powerful, and more automatable than a graphical interface.

Why Developers Use the Terminal

The terminal gives you direct access to every tool in your development stack: running programs, managing files, using Git, starting servers, installing packages, and running tests. GUI tools show you a curated subset of options; the terminal gives you everything. Once you learn the commands, you can work faster than with a mouse — and you can script sequences of commands to automate repetitive tasks.

Essential Commands

Here are the commands you will use every day:

| Command | What it does | |---------|-------------| | pwd | Print working directory — where am I? | | ls | List files in the current directory | | cd folder | Change directory — move into folder | | cd .. | Move up one directory | | mkdir name | Create a new directory | | touch file.js | Create an empty file | | cat file | Print a file's contents to the screen | | rm file | Remove (delete) a file | | cp src dest | Copy a file | | mv src dest | Move or rename a file |

Navigating the Filesystem

The terminal is always "in" a specific directory — your working directory. pwd tells you where you are. ls shows what is here. cd moves you somewhere else. You can use relative paths (cd src/components — relative to where you are) or absolute paths (cd /home/user/project — starting from the root).

Piping and Redirection

Two powerful features let you combine commands:

  • Redirection (>) sends output to a file instead of the screen: ls > files.txt saves the listing to a file.
  • Pipe (|) sends the output of one command as input to another: cat data.json | head -5 shows the first 5 lines of a file.

Pipes are the Unix philosophy in action: small, focused commands that do one thing well, combined to solve complex tasks.

The Development Workflow

A typical developer session in the terminal looks like this: cd my-project to enter the project, git pull to get the latest code, npm install to install dependencies, npm test to run tests, npm run dev to start the dev server. Every one of these is a command-line operation. Learning the terminal is not optional for a developer — it is the environment where your code lives.

Example

              # Navigate to a project and explore its structure
pwd                          # /home/user
cd projects/my-app           # move into the project
ls                           # see what's here
# package.json  src/  tests/  README.md

# Look at a file's contents
cat package.json             # print the whole file
head -5 package.json         # first 5 lines only

# Create a new directory and file for a feature
mkdir src/features/auth
touch src/features/auth/login.js

# Search for a function across all JavaScript files
grep -r "function login" src/
# src/features/auth/login.js:function login(user) {

# Combine commands with a pipe: count JavaScript files
ls src/**/*.js | wc -l       # e.g., 42

# Run the project's test suite
npm test
            

This session demonstrates navigation (cd, ls, pwd), file inspection (cat, head), file creation (mkdir, touch), searching (grep), piping (|), and running a project command (npm test). These are the daily operations of a developer.

Try it

  • Crontab Generator

    Cron schedules are configured in the terminal. Generate and understand cron expressions used in command-line scheduling.

  • HTTP Request Tester

    Testing APIs from the command line (with curl) is a core skill. This tool gives you a GUI equivalent of curl commands.

Common mistakes

The mistake

Using rm on files without being sure of the path.

The fix

The terminal has no undo. Always check with ls first, and use rm -i (interactive mode) which asks for confirmation. Never run rm -rf / or similar destructive commands without understanding them fully.

The mistake

Getting lost in the filesystem with cd.

The fix

Use pwd to check where you are. Use cd with no arguments to return home, or cd ~. Tab-completion (press Tab while typing a path) prevents typos and speeds up navigation.

The mistake

Memorizing commands without understanding what they do.

The fix

Use man command (manual) or command --help to read what a command does and its options. Understanding the concepts behind commands is more durable than rote memorization.

Related Cheatsheets

  • Bash Cheatsheet

    Complete reference for shell commands, piping, redirection, and scripting.

  • Git Cheatsheet

    Git is a command-line tool — learn the version control commands you will use daily.

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors