Using a Terminal

Get familiar with using a terminal application and a command line shell.
Author

Chuck Nelson

Published

August 26, 2025

Using a terminal

What is a Terminal?

A terminal (also called a command line interface or CLI) is a text-based interface that allows you to interact with your computer’s operating system using typed commands instead of clicking on graphical elements. Think of it as having a direct conversation with your computer using a specialized language.

ImportantKey Concept

The terminal is one of the most powerful tools in computing. While it may seem intimidating at first, mastering the command line will make you significantly more efficient and give you access to advanced system capabilities.

Terminal vs. Shell vs. Environment

Before we dive deeper, let’s clarify some important terminology:

NoteEssential Terminology
  • Terminal: The application window that provides the interface for text input/output
  • Shell: The command interpreter that processes your commands and communicates with the operating system
  • Environment: The collection of variables and settings that define how your shell and programs behave

Understanding System Architecture

When you use a terminal, you’re operating in what’s called userspace - the area where user applications run. Your commands travel through several layers:

  1. Userspace: Where you type commands and applications run
  2. Shell: Interprets your commands
  3. System Calls: Interface between userspace and kernel
  4. Kernel Space: The core of the operating system that manages hardware
NoteWhy System Architecture Matters

Understanding this architecture helps you troubleshoot issues and understand why certain commands require elevated permissions (sudo/Administrator) - they need to access kernel space.

Opening Your Terminal

The method for opening a terminal varies by operating system:

Debian-based (Ubuntu, Debian, Linux Mint):

  • Press Ctrl + Alt + T
  • Or search for “Terminal” in applications
  • Or right-click on desktop → “Open Terminal”
  • Default terminal: usually gnome-terminal

Red Hat-based (RHEL, CentOS, Fedora):

  • Press Ctrl + Alt + T
  • Or search for “Terminal” in applications
  • Or press Alt + F2, type gnome-terminal or konsole
  • Fedora may use gnome-terminal or konsole depending on desktop

Alternative Method (All Distributions):

  • Press Alt + F2, type gnome-terminal, konsole, or xterm

Command Prompt:

  • Press Win + R, type cmd, press Enter
  • Or press Win + X, select “Command Prompt”

PowerShell (Recommended):

  • Press Win + X, select “PowerShell”
  • Or search “PowerShell” in Start menu

Windows Terminal (Modern Option):

  • Search “Windows Terminal” in Start menu
  • Provides tabs and better features

Built-in Terminal:

  • Press Cmd + Space, type “Terminal”, press Enter
  • Or go to Applications → Utilities → Terminal
  • Or press Cmd + Space, type “iTerm” if installed

Alternative:

  • Many developers prefer iTerm2 (downloadable)

Understanding Your Shell

What is a Shell?

A shell is a command-line interpreter that:

  • Reads commands you type
  • Interprets and executes them
  • Returns results to you
  • Manages environment variables and settings

Default Shells by Operating System

Understanding the default shell for each operating system helps set proper expectations:

TipDefault Shells by Platform
  • Linux: bash (Bourne Again Shell) - most distributions
  • macOS: zsh (Z Shell) - since macOS Catalina (10.15), previously bash
  • Windows: cmd (Command Prompt) - traditional default, with PowerShell increasingly common

Identifying Your Current Shell

# Check current shell
echo $SHELL

# Alternative method
ps -p $$

# See available shells
cat /etc/shells

Common shells:

  • bash - Bourne Again Shell (default on most Linux distributions)
  • zsh - Z Shell (macOS default since Catalina, growing Linux adoption)
  • fish - Friendly Interactive Shell
  • sh - Original Bourne Shell
  • dash - Debian Almquist Shell (Ubuntu’s /bin/sh)
NoteDistribution-Specific Shell Notes
  • Debian/Ubuntu: Default user shell is bash, but /bin/sh points to dash
  • Red Hat/CentOS/Fedora: Default user shell is bash
  • Arch Linux: Default is bash, but zsh is popular
# In PowerShell
$PSVersionTable

# In Command Prompt
echo %COMSPEC%

Windows shells:

  • cmd - Command Prompt (traditional default)
  • powershell - Windows PowerShell (increasingly default)
  • pwsh - PowerShell Core (cross-platform, latest version)

Changing Your Shell

WarningImportant Note

Changing your default shell affects all new terminal sessions. Make sure you understand the implications before making changes.

# Temporarily switch to a different shell
bash
zsh
fish

# Change default shell permanently
chsh -s /bin/bash      # Switch to bash
chsh -s /bin/zsh       # Switch to zsh

# Verify the change (may require logout/login)
echo $SHELL
# You can start different shells from within each other
cmd          # Start Command Prompt from PowerShell
powershell   # Start PowerShell from Command Prompt
pwsh         # Start PowerShell Core (if installed)

# Exit to return to previous shell
exit

Shell Recommendation: Zsh with Oh My Zsh

For Linux and macOS users, we highly recommend upgrading to Zsh (Z Shell) with Oh My Zsh for a significantly enhanced terminal experience.

TipWhy Choose Zsh + Oh My Zsh?

Zsh advantages over bash:

  • Better tab completion (case-insensitive, typo correction)
  • Improved globbing and pattern matching
  • Built-in spell checking
  • Better history management
  • Plugin and theme support
  • Smart command suggestions

Oh My Zsh benefits:

  • Easy theme customization
  • Hundreds of useful plugins
  • Git integration with status indicators
  • Syntax highlighting
  • Auto-suggestions based on history

Installing Zsh and Oh My Zsh

# Install zsh
sudo apt update
sudo apt install zsh

# Verify installation
zsh --version

# Install Oh My Zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# Change default shell to zsh
chsh -s $(which zsh)

# Log out and back in, or restart terminal
# Install zsh
# RHEL/CentOS 8+/Fedora:
sudo dnf install zsh

# RHEL/CentOS 7:
sudo yum install zsh

# Verify installation
zsh --version

# Install Oh My Zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# Change default shell to zsh
chsh -s $(which zsh)

# Log out and back in, or restart terminal
# Zsh is already installed on macOS Catalina+
# For older macOS versions, install via Homebrew:
brew install zsh

# Install Oh My Zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# Zsh should already be your default shell on modern macOS
# If not, change it:
chsh -s $(which zsh)

Environment Variables

Environment variables are dynamic values that affect how programs run on your system. They store information like system paths, user preferences, and configuration settings.

ImportantCritical Environment Variables

$PATH / %PATH%

The most important environment variable - tells the system where to find executable programs.

$SHELL / %COMSPEC%

Specifies your default shell program.

$JAVA_HOME / %JAVA_HOME%

Points to your Java installation directory (when Java is installed).

Viewing Environment Variables

# View a specific environment variable
echo $PATH
echo $SHELL
echo $JAVA_HOME
echo $HOME
echo $USER

# View all environment variables
env
# or
printenv

# View all variables (including shell variables)
set
REM View a specific environment variable
echo %PATH%
echo %COMSPEC%
echo %JAVA_HOME%
echo %USERNAME%
echo %USERPROFILE%

REM View all environment variables
set

REM View specific variable
set PATH
# View a specific environment variable
$env:PATH
$env:JAVA_HOME
$env:USERNAME
$env:USERPROFILE

# View all environment variables
Get-ChildItem Env:

# Alternative syntax
echo $env:PATH

Understanding $PATH

The PATH variable is crucial - it’s a list of directories where the system looks for executable files.

WarningUnderstanding PATH

When you type a command like python or git, your system searches through each directory listed in PATH (in order) until it finds the executable. If the program isn’t in any PATH directory, you’ll get a “command not found” error.

# View PATH (colon-separated)
echo $PATH

# View PATH in readable format
echo $PATH | tr ':' '\n'

# Add a directory to PATH temporarily
export PATH=$PATH:/new/directory/path

# Add to PATH permanently (add to ~/.bashrc or ~/.zshrc)
echo 'export PATH=$PATH:/new/directory/path' >> ~/.bashrc
# View PATH (semicolon-separated) in PowerShell
$env:PATH -split ';'

# Add to PATH temporarily in PowerShell
$env:PATH += ";C:\new\directory\path"

# View PATH in Command Prompt
echo %PATH%

File System Navigation

Basic Navigation Commands

# Print current directory
pwd

# List files and directories
ls                    # Basic listing
ls -l                 # Long format (detailed)
ls -la                # Long format including hidden files
ls -lh                # Long format with human-readable sizes

# Change directory
cd /home/username     # Absolute path
cd Documents          # Relative path
cd ..                 # Go up one directory
cd ~                  # Go to home directory
cd -                  # Go to previous directory

# Create directories
mkdir new_folder
mkdir -p path/to/nested/folders

# Create files
touch newfile.txt
echo "Hello" > newfile.txt
REM Print current directory
cd
REM or
echo %CD%

REM List files and directories
dir                   REM Basic listing
dir /a                REM Show all files including hidden
dir /w                REM Wide format

REM Change directory
cd C:\Users\username  REM Absolute path
cd Documents          REM Relative path
cd ..                 REM Go up one directory
cd \                  REM Go to root directory

REM Create directories
mkdir new_folder
md nested\folder\path

REM Create files
echo Hello > newfile.txt
type nul > emptyfile.txt
# Print current directory
Get-Location
# or
pwd

# List files and directories
Get-ChildItem         # Basic listing
Get-ChildItem -Force  # Include hidden files
ls                    # Alias for Get-ChildItem
dir                   # Another alias

# Change directory
Set-Location C:\Users\username  # Absolute path
Set-Location Documents          # Relative path
cd ..                          # Go up one directory
cd ~                           # Go to home directory

# Create directories
New-Item -ItemType Directory -Name "new_folder"
mkdir new_folder               # Alias

# Create files
New-Item -ItemType File -Name "newfile.txt"
echo "Hello" > newfile.txt

File Management

Basic File Operations

# Copy files
cp source.txt destination.txt
cp -r source_folder destination_folder  # Copy directories recursively

# Move/rename files
mv oldname.txt newname.txt
mv file.txt /path/to/destination/

# Delete files
rm file.txt
rm -r folder/        # Remove directory and contents
rm -rf folder/       # Force remove (be careful!)

# View file contents
cat file.txt         # Display entire file
less file.txt        # View file page by page (q to quit)
head file.txt        # Show first 10 lines
tail file.txt        # Show last 10 lines

# Find files
find . -name "*.txt"           # Find all .txt files
find /home -name "filename"    # Find specific file
REM Copy files
copy source.txt destination.txt
xcopy source_folder destination_folder /E  REM Copy directories

REM Move/rename files
move oldname.txt newname.txt
ren oldname.txt newname.txt     REM Rename only

REM Delete files
del file.txt
rmdir folder         REM Remove empty directory
rmdir /S folder      REM Remove directory and contents

REM View file contents
type file.txt        REM Display entire file
more file.txt        REM View file page by page

REM Find files
dir *.txt /S         REM Find all .txt files recursively
where filename       REM Find file in PATH
# Copy files
Copy-Item source.txt destination.txt
Copy-Item source_folder destination_folder -Recurse

# Move/rename files
Move-Item oldname.txt newname.txt
Rename-Item oldname.txt newname.txt

# Delete files
Remove-Item file.txt
Remove-Item folder -Recurse    # Remove directory and contents

# View file contents
Get-Content file.txt           # Display entire file
Get-Content file.txt | more    # View page by page

# Find files
Get-ChildItem -Recurse -Filter "*.txt"
Get-ChildItem -Path C:\ -Recurse -Name "*filename*"

Running Executable Files

Understanding Executables

Different operating systems handle executable files differently:

NoteExecutable File Types by Platform
  • Linux/macOS: Files with execute permissions, scripts with shebang (#!/bin/bash)
  • Windows: Files with extensions like .exe, .bat, .cmd, .ps1

Running Programs

# Run executable in current directory
./program_name
./script.sh

# Run program in PATH
program_name
python3 script.py
node app.js

# Make file executable
chmod +x script.sh

# Run with specific interpreter
bash script.sh
python3 program.py

# Check if command exists
which python3
command -v git
REM Run executable in current directory
program_name.exe
script.bat

REM Run program in PATH
notepad
python script.py
node app.js

REM Run PowerShell script from Command Prompt
powershell -ExecutionPolicy Bypass -File script.ps1

REM Check if command exists
where python
where git
# Run executable in current directory
.\program_name.exe
.\script.ps1

# Run program in PATH
notepad
python script.py
node app.js

# Set execution policy (may require admin)
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

# Check if command exists
Get-Command python
Get-Command git -ErrorAction SilentlyContinue

Working with $JAVA_HOME

If you have Java installed, the JAVA_HOME environment variable should point to your Java installation:

# Check if JAVA_HOME is set
echo $JAVA_HOME

# If not set, find Java installation
which java
/usr/libexec/java_home    # macOS specific

# Set JAVA_HOME temporarily
export JAVA_HOME=/path/to/java/home

# Add to shell profile permanently
echo 'export JAVA_HOME=/path/to/java/home' >> ~/.bashrc
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc
# Check if JAVA_HOME is set
echo $env:JAVA_HOME

# Set JAVA_HOME temporarily in PowerShell
$env:JAVA_HOME = "C:\Program Files\Java\jdk-17"

# Set permanently (requires admin or user environment variables)
[Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Program Files\Java\jdk-17", "User")

Practical Exercises

CautionBefore You Begin

Create a backup of important files and work in a test directory. These exercises are designed to be safe, but it’s always good practice to be cautious when learning new commands.

Exercise 1: Environment Exploration

  1. Open your terminal
  2. Identify your current shell
  3. Display your PATH variable in a readable format
  4. Check if JAVA_HOME is set
  5. Find your home directory path
TipExpected Results

You should see your shell (likely bash, zsh, or cmd), a list of directories in your PATH, and your home directory location. JAVA_HOME may or may not be set depending on your system.

Exercise 2: File System Navigation

  1. Navigate to your home directory
  2. Create a new directory called “terminal_practice”
  3. Navigate into that directory
  4. Create three files: file1.txt, file2.txt, script.sh
  5. List all files to confirm creation
TipVerification Step

Use ls (Linux/macOS) or dir (Windows) to confirm all files were created successfully.

Exercise 3: Basic File Management

  1. Copy file1.txt to file1_backup.txt
  2. Rename file2.txt to renamed_file.txt
  3. Create a subdirectory called backup
  4. Move file1_backup.txt into the backup directory
  5. Remove the original file1.txt
WarningFile Deletion Warning

The rm command (Linux/macOS) and del command (Windows) permanently delete files. There’s no “recycle bin” recovery from the command line, so double-check your commands before pressing Enter.

Exercise 4: Running Programs

  1. Create a simple script file
  2. Make it executable (Linux/macOS)
  3. Run the script from the command line
  4. Try running a system program like python or node (if installed)
NoteTroubleshooting

If you get “command not found” errors, the program may not be installed or not in your PATH. This is normal and expected for programs that aren’t installed on your system.

Tips and Best Practices

TipPro Tips for Terminal Mastery
  1. Use Tab Completion: Press Tab while typing to auto-complete file/directory names
  2. Command History: Use Up/Down arrows to navigate through previous commands
  3. Clear Screen: Type clear (Linux/macOS) or cls (Windows) to clear the terminal
  4. Stop Running Programs: Press Ctrl+C to interrupt running programs
  5. Multiple Terminals: Open multiple terminal windows/tabs for complex tasks
  6. Manual Pages: Use man command (Linux/macOS) or Get-Help command (PowerShell) for help
WarningSafety and Security Reminders
  1. Be Careful with Deletion Commands: rm, del, and Remove-Item permanently delete files
  2. Verify Paths: Always confirm you’re in the correct directory before running commands
  3. Backup Important Files: Before experimenting, make copies of important data
  4. Understand Permissions: Some commands require administrator/sudo privileges
  5. Never Run Unknown Scripts: Only execute code you understand or trust
  6. Double-Check Destructive Commands: Take a moment to review commands that modify or delete files

Summary

ImportantKey Learning Outcomes

You’ve learned the fundamentals of working with terminals and shells:

  • Terminal: Your text-based interface to the computer
  • Shell: The command interpreter (bash, zsh, PowerShell, etc.)
  • Environment Variables: Dynamic values that affect program behavior
  • File Navigation: Moving around the filesystem with commands
  • File Management: Creating, copying, moving, and deleting files
  • Running Executables: Executing programs from the command line

These skills form the foundation for system administration, development, and advanced computing tasks. Practice regularly to build your confidence and efficiency with command-line interfaces.

NoteNext Steps

The terminal might seem intimidating at first, but with practice, you’ll find it’s often faster and more powerful than graphical interfaces for many tasks. Consider setting up Zsh with Oh My Zsh for an enhanced experience, and don’t hesitate to explore the many powerful command-line tools available for your platform.

Back to top