How to Use the Terminal and Command Line for Beginners

11 min read Developer Guides

Table of Contents

The terminal is one of the most powerful tools available to any computer user, yet many beginners avoid it because it looks intimidating. There is no graphical interface, no buttons to click—just a blinking cursor waiting for instructions. But once you learn a handful of commands, you will find that the terminal is often faster and more precise than any graphical tool.

This guide covers everything you need to get started: opening the terminal on your operating system, understanding how commands work, navigating the file system, manipulating files, and using more advanced features like piping, environment variables, and package managers.

What Is the Terminal?

The terminal (also called the command line, console, or shell) is a text-based interface for interacting with your computer. Instead of clicking icons, you type commands that the operating system executes. The program that interprets those commands is called a shell.

Common shells include:

  • Bash – The default shell on most Linux distributions and older macOS versions
  • Zsh – The default shell on macOS since Catalina, with enhanced features like better autocomplete
  • PowerShell – The modern shell for Windows, included with Windows 10 and later
  • Fish – A user-friendly shell with syntax highlighting and auto-suggestions out of the box

Regardless of which shell you use, the fundamental concepts—commands, arguments, flags, and file paths—work the same way.

Opening the Terminal

Windows

  • Windows Terminal: Press Win + X and select Terminal. Windows Terminal supports PowerShell, Command Prompt, and WSL tabs in a single window.
  • PowerShell: Search for “PowerShell” in the Start menu.
  • Command Prompt: Search for “cmd” in the Start menu (older, limited compared to PowerShell).
  • WSL (Windows Subsystem for Linux): If you need a Linux environment, install WSL from the Microsoft Store and open a Linux terminal from Windows Terminal.

macOS

  • Open Finder, go to Applications > Utilities > Terminal.
  • Alternatively, press Cmd + Space to open Spotlight, type “Terminal,” and press Enter.
  • For a more feature-rich experience, download iTerm2, a popular third-party terminal emulator for macOS.

Linux

  • Most desktop environments include a terminal app. Look for “Terminal,” “Console,” or “Konsole” in your application menu.
  • The keyboard shortcut Ctrl + Alt + T opens the terminal on many distributions.

Anatomy of a Command

Every command follows a general structure:

command [options] [arguments]
  • command is the program you want to run (e.g., ls, cd, mkdir).
  • options (also called flags) modify the command’s behavior. They usually start with a dash (-l) or double dash (--long).
  • arguments tell the command what to operate on (e.g., a file name or directory path).

Example:

ls -la /home/user/Documents

This runs the ls command with the -l (long listing) and -a (show hidden files) flags, targeting the /home/user/Documents directory.

Navigating the File System

Checking Your Current Directory

# macOS / Linux
pwd

# Windows PowerShell
Get-Location    # or simply: pwd (alias works in PowerShell too)

pwd stands for “print working directory” and shows the full path of the folder you are currently in.

Listing Files and Folders

# macOS / Linux
ls           # Basic listing
ls -la       # Long format with hidden files

# Windows PowerShell
Get-ChildItem    # or: dir / ls (aliases)

Changing Directories

cd Documents           # Move into the Documents folder
cd ..                  # Move up one level
cd ~                   # Go to your home directory (macOS/Linux)
cd /                   # Go to the root of the file system
cd "My Folder"         # Use quotes for folders with spaces

Think of the file system as a tree. The root is at the top, and you navigate down through branches (folders) and back up with cd ... The tilde (~) is a shortcut to your home directory.

Working with Files and Directories

Creating Directories

mkdir my-project                 # Create a single directory
mkdir -p projects/web/assets     # Create nested directories (-p creates parents)

Creating Files

# macOS / Linux
touch index.html                 # Create an empty file

# Windows PowerShell
New-Item index.html -ItemType File

Viewing File Contents

# macOS / Linux
cat readme.txt            # Print entire file to the terminal
less readme.txt           # View file with scrolling (press q to quit)
head -n 20 readme.txt     # Show the first 20 lines
tail -n 20 readme.txt     # Show the last 20 lines

# Windows PowerShell
Get-Content readme.txt    # or: cat readme.txt (alias)

Copying Files and Directories

# macOS / Linux
cp file.txt backup.txt              # Copy a file
cp -r my-folder my-folder-backup    # Copy a directory recursively

# Windows PowerShell
Copy-Item file.txt backup.txt
Copy-Item my-folder my-folder-backup -Recurse

Moving and Renaming

# macOS / Linux
mv old-name.txt new-name.txt        # Rename a file
mv file.txt ../other-folder/        # Move a file to another folder

# Windows PowerShell
Move-Item old-name.txt new-name.txt
Move-Item file.txt ..\other-folder\

Deleting Files and Directories

# macOS / Linux
rm file.txt                         # Delete a file
rm -r my-folder                     # Delete a directory and its contents
rm -i file.txt                      # Ask for confirmation before deleting

# Windows PowerShell
Remove-Item file.txt
Remove-Item my-folder -Recurse

Warning: The terminal does not have a recycle bin. When you delete a file with rm, it is gone permanently. Always double-check before running delete commands, especially with the -r flag.

Searching for Files and Text

Finding Files

# macOS / Linux
find . -name "*.txt"                # Find all .txt files in the current directory tree

# Windows PowerShell
Get-ChildItem -Recurse -Filter "*.txt"

Searching Inside Files

# macOS / Linux
grep "error" log.txt                # Find lines containing "error" in log.txt
grep -r "TODO" ./src                # Recursively search all files in ./src

# Windows PowerShell
Select-String -Pattern "error" -Path log.txt

Environment Variables

Environment variables are key-value pairs that configure your shell session and the programs that run in it. Common examples include PATH (the list of directories searched for executable programs), HOME (your home directory), and custom variables for API keys.

Viewing Environment Variables

# macOS / Linux
echo $PATH
echo $HOME
env                    # List all environment variables

# Windows PowerShell
echo $env:PATH
echo $env:USERPROFILE
Get-ChildItem Env:     # List all environment variables

Setting Environment Variables

# macOS / Linux (temporary, current session only)
export API_KEY="your-key-here"

# To make it permanent, add the export line to ~/.bashrc or ~/.zshrc

# Windows PowerShell (temporary)
$env:API_KEY = "your-key-here"

# To set permanently on Windows, use System Properties > Environment Variables

Piping and Redirecting Output

One of the terminal’s most powerful features is the ability to chain commands together using pipes (|) and redirect output to files.

Piping

A pipe takes the output of one command and feeds it as input to the next:

# Count the number of JavaScript files in a project
find . -name "*.js" | wc -l

# View a long directory listing one page at a time
ls -la | less

# Filter running processes for a specific program
ps aux | grep node

Redirecting Output

# Write command output to a file (overwrites existing content)
ls -la > file-list.txt

# Append output to a file
echo "New log entry" >> app.log

# Redirect errors to a file
npm run build 2> errors.log

# Redirect both standard output and errors
npm run build > output.log 2>&1

Package Managers

Package managers let you install, update, and remove software from the command line. They handle dependencies automatically, making software management far simpler than downloading installers manually.

macOS: Homebrew

# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install a program
brew install git
brew install node

# Update all packages
brew update && brew upgrade

Linux: APT (Debian/Ubuntu)

sudo apt update                    # Refresh the package index
sudo apt install git               # Install a package
sudo apt upgrade                   # Upgrade all installed packages

Windows: winget

winget search vscode               # Search for a package
winget install Microsoft.VisualStudioCode   # Install a package
winget upgrade --all               # Upgrade all installed packages

Useful Keyboard Shortcuts

Learning these shortcuts will make you significantly faster in the terminal:

  • Tab – Autocomplete file names and commands
  • Ctrl + C – Cancel the currently running command
  • Ctrl + L – Clear the terminal screen
  • Ctrl + A – Move the cursor to the beginning of the line
  • Ctrl + E – Move the cursor to the end of the line
  • Ctrl + R – Search through your command history
  • Up Arrow – Cycle through previous commands
  • !! – Repeat the last command (Bash/Zsh)

Practical Tips for Beginners

  • Start small. Practice navigating folders and creating files before attempting complex operations.
  • Use Tab completion. Press Tab after typing a few characters to autocomplete paths and commands. This prevents typos and saves time.
  • Read the manual. Most commands have built-in documentation. Run man ls on macOS/Linux or Get-Help Get-ChildItem on PowerShell to learn all available options.
  • Be careful with rm. Always double-check what you are deleting. Use rm -i to enable confirmation prompts until you are confident.
  • Customize your shell. Add aliases to your shell configuration file for commands you use frequently. For example, add alias ll="ls -la" to your ~/.zshrc.
  • Use version control. Once you are comfortable with the terminal, learn Git. Nearly all Git workflows are performed from the command line, and the skills you are building now will transfer directly.

What to Learn Next

Once you are comfortable with the basics covered in this guide, consider exploring these topics:

  • Shell scripting: Write Bash or PowerShell scripts to automate repetitive tasks.
  • SSH: Connect to remote servers securely from your terminal.
  • Git: Version control your code using command-line Git.
  • Docker: Build and run containerized applications from the terminal.
  • tmux or screen: Manage multiple terminal sessions within a single window.

Conclusion

The terminal is not as scary as it first appears. With a handful of commands—cd, ls, mkdir, cp, mv, rm, and cat—you can navigate your file system, manage files, and accomplish tasks faster than clicking through a graphical interface. Piping, environment variables, and package managers add even more power to your workflow.

The key is consistent practice. Open the terminal, try the commands from this guide, and gradually replace graphical tasks with command-line equivalents. Before long, the blinking cursor will feel less like an obstacle and more like a superpower.

Related Articles