Bash Get Started

Setting up your Bash environment

🚀 Getting Started with Bash

Starting with Bash is simple and requires minimal setup. Access the terminal on your system, verify Bash installation, and begin executing commands immediately. Most Unix-based systems come with Bash pre-installed and ready to use.


# Check if Bash is installed
bash --version
                                    

Output:

GNU bash, version 5.1.16(1)-release

Accessing the Terminal

🐧

Linux

Press Ctrl+Alt+T or search for "Terminal"

GNOME Terminal Konsole xterm
🍎

macOS

Open Terminal from Applications/Utilities

Terminal iTerm2 Hyper
🪟

Windows

Use WSL, Git Bash, or Cygwin

WSL Git Bash Cygwin
☁️

Online

Practice in browser-based terminals

Repl.it JSLinux Webminal

🔹 Your First Commands

Basic Bash commands form the foundation of terminal navigation and file management. Essential commands include pwd (print working directory), ls (list files), cd (change directory), cat (display file contents), and mkdir (create directories). Practice these commands to understand your file system structure and build confidence with command-line operations. Mastering these fundamentals prepares you for more advanced scripting, system administration, and automation tasks that rely on efficient file system navigation and manipulation.


# Display current directory
pwd

# List files in current directory
ls

# Show current user
whoami

# Display calendar
cal

# Show current date and time
date

# Clear the screen
clear
                            

Output:

/home/john
Documents  Downloads  Pictures
john
    October 2025
Su Mo Tu We Th Fr Sa
          1  2  3  4
 5  6  7  8  9 10 11
Wed Oct  8 14:30:22 UTC 2025

🔹 Understanding the Prompt

The Bash prompt provides crucial context about your current shell session and system status. Typically displaying username, hostname, current directory, and sometimes additional information, the prompt helps you navigate safely and efficiently. Custom prompts can include timestamps, git branch status, battery levels, or success indicators from previous commands. Learning to interpret your prompt prevents errors by ensuring you're operating in the correct directory and with appropriate user privileges, especially when performing system administration tasks.


# Common prompt formats:
# username@hostname:current_directory$

# Example prompts:
john@laptop:~$              # Regular user
root@server:/home/john#     # Root user
user@host:/var/www$         # In specific directory

# The prompt symbols:
# $ - Regular user
# # - Root/superuser

# Check your prompt
echo $PS1
                            

Example:

john@laptop:~$ 

🔹 Basic Navigation

Efficient file system navigation is essential for productive command-line work. Use cd with relative paths (cd Documents), absolute paths (cd /home/user/Documents), or special symbols (cd ~ for home, cd - for previous directory). Combine with ls to explore contents and pwd to confirm location. Understanding path resolution, directory hierarchy, and navigation shortcuts enables quick movement between project directories and system locations, significantly improving your terminal workflow efficiency.


# Change to home directory
cd ~
cd

# Go to specific directory
cd /usr/local/bin

# Go up one level
cd ..

# Go to previous directory
cd -

# Show current directory
pwd

# List directory contents
ls
ls -l      # Detailed list
ls -la     # Include hidden files
                            

Output:

/home/john
/usr/local/bin
/usr/local
/usr/local/bin
Documents  Downloads  Music  Pictures

🔹 Getting Help

Bash provides comprehensive help systems for learning commands and troubleshooting issues. Use man command for detailed manuals, command --help for quick reference, help for shell builtins, and apropos to find relevant commands. These resources explain syntax, options, examples, and related commands. Developing proficiency with help systems enables self-directed learning and problem-solving, reducing dependency on external documentation and building deeper understanding of command-line tools and their capabilities.


# View manual page for a command
man ls
man bash

# Quick help for a command
ls --help
date --help

# Get information about built-in commands
help cd
help echo

# Search for commands
apropos "list directory"
                            

Output:

LS(1)                    User Commands
NAME
       ls - list directory contents
SYNOPSIS
       ls [OPTION]... [FILE]...

🔹 Command History

Efficiently accessing and searching command history saves time and prevents retyping errors. Browse sequentially with up/down arrows. Search interactively in reverse with Ctrl+R. Use !! to rerun the last command or !string to run the last command starting with 'string'. Access arguments from the previous command with Alt+.. This deep integration with your command past accelerates workflow, facilitates complex command reuse, and serves as a practical memory aid for your terminal activities.


# View command history
history

# Show last 10 commands
history 10

# Execute previous command
!!

# Execute command number 42
!42

# Search history (press Ctrl+R)
# Then type to search

# Clear history
history -c
                            

Output:

  1  ls -la
  2  cd Documents
  3  pwd
  4  date
  5  history

🔹 Tab Completion

Tab completion accelerates command entry and reduces errors by auto-filling commands, filenames, and paths. Press Tab once to complete the current word; press it twice to list all possible completions. It works for commands in your PATH, files/directories in the current directory, and even variable names. This feature not only speeds up typing but also acts as a discovery tool and a guard against typos in critical commands or file paths, making shell interaction faster and more accurate.


# Type partial command and press Tab
cd Doc[Tab]        # Completes to: cd Documents/

# Double Tab shows options
ls Do[Tab][Tab]    # Shows: Documents/ Downloads/

# Complete command names
dat[Tab]           # Completes to: date

# Works with file names
cat my_fi[Tab]     # Completes to: cat my_file.txt
                            

Tab Completion Tips:

  • Press Tab once for single match completion
  • Press Tab twice to see all possible matches
  • Works with commands, files, and directories
  • Case-sensitive on Linux/macOS

🧠 Test Your Knowledge

Which command shows your current directory?