Bash Cheat Sheet

Bash Cheat Sheet: Linux Commands and Scripting Guide

Jashan
October 8th, 2026
1798
10:00 Minutes

This Bash cheat sheet is a quick-reference guide to the most useful Bash (Bourne Again SHell) commands, syntax and scripting basics. Whether you are a beginner learning the terminal, a developer working on servers, or a DevOps engineer writing automation scripts, you can use this Bash commands cheat sheet for fast revision, interview preparation and daily work. Each section includes short explanations and copy-ready examples. Let’s begin!

It focuses on the important commands you will actually use while working with Linux systems, servers or development environments. Each section is written in simple language and structured for fast revision, which makes it useful for learning, interview preparation and daily terminal usage.

Bash Cheat Sheet at a Glance

Use this table as a quick Bash commands cheat sheet. Each command is explained in detail in the sections below.

TaskCommandWhat It Does
Navigationpwd, ls, cdShow, list and change directories
Filesmkdir, touch, cp, mv, rmCreate, copy, move and delete
View filescat, less, head, tailRead file contents
Permissionschmod, chownControl access and ownership
Searchgrep, find, awk, sedSearch and transform text
Processesps, top, kill, jobsMonitor and control processes
Networkcurl, ping, ssh, scpConnect and transfer data
Diskdf, duCheck storage usage
Scriptingif, for, while, functionLogic, loops and reusable code

What is Bash?

Bash is a command-line interpreter used to interact with Unix-based operating systems such as Linux and macOS. It allows users to execute commands, automate tasks using scripts, manage files, control processes and work efficiently without a graphical interface. Bash is available on Linux, on macOS (where zsh is now the default shell but Bash is still installed), and on Windows through WSL or Git Bash.

Bash is mostly used by developers, system administrators and DevOps engineers due to its powerful text processing, job control and scripting capabilities. It is also the default shell in most Linux distributions. This makes it essential to learn for anyone working with servers, cloud platforms or open-source systems.

In real-world environments, Bash is widely used to manage cloud servers, automate deployments and monitor application logs. System administrators often use Bash to troubleshoot production issues while DevOps engineers rely on Bash scripts inside CI/CD pipelines to automate repetitive infrastructure tasks.

Basic Bash Commands

Basic Bash commands are used for everyday tasks like navigating directories, managing files and viewing system information. These commands form the foundation of Bash usage and are usually the first things beginners learn.

Understanding them helps users move around the file system, create or delete files and check where they are working from within the terminal.

Common Bash Commands

  • pwd – Shows the current directory
  • ls – Lists files and folders
  • cd – Changes directory
  • clear – Clears the terminal screen

pwd
ls
cd Documents

File and Directory Management

File and directory management commands help users create, copy, move, rename and delete files or folders. These commands are critical when working on servers where graphical file managers are unavailable. Bash provides simple yet powerful tools to handle large directory structures efficiently.

Key Commands

  • mkdir – Create a directory
  • rmdir – Remove empty directory
  • touch – Create an empty file
  • cp – Copy files
  • mv – Move or rename files

mkdir projects
touch notes.txt
cp notes.txt backup.txt
mv backup.txt archive.txt

Note: Be careful while using delete commands such as rm, especially with options like -r or -rf, because they permanently remove files and directories. Always double-check the path before executing destructive commands.

Viewing and Reading Files

Bash provides multiple commands to view file contents without opening them in an editor. These commands allow quick inspection of logs, configuration files, and text data, which is especially useful for troubleshooting and monitoring systems.

Common Commands

  • cat – Displays full file content
  • less – Scroll through file content
  • more – Page-by-page view
  • head – Shows first lines of a file
  • tail – Shows last lines of a file
  • tail -f – Follows a log file live as new lines are added

cat file.txt
head -5 file.txt
tail -10 file.txt

File Permissions and Ownership

Linux file permissions control who can read, write or execute a file. Bash commands like chmod and chown let you manage them, which enhances system security by restricting unauthorized access. Understanding permissions is essential when working with scripts, shared servers and production environments.

Important Commands

  • chmod – Change file permissions
  • chown – Change file owner
  • ls -l – View permissions

touch demo.txt
ls -l demo.txt
chmod 600 demo.txt
ls -l demo.txt

In the example above, chmod 600 gives the owner read and write access and removes all access for everyone else. Another common value is chmod 755, which gives the owner full access and lets everyone else read and execute the file. It is widely used for scripts.

Searching and Text Processing

Bash offers powerful text-search and processing tools that allow users to filter, search and manipulate text files. These commands are heavily used in log analysis, data processing and automation tasks.

Common Commands

  • grep – Search text patterns
  • wc – Count lines, words, characters
  • sort – Sort lines
  • uniq – Remove duplicates

grep "error" log.txt
wc -l log.txt
sort names.txt | uniq

Input/Output Redirection and Pipes in Bash

Redirection sends command output to files, and pipes pass the output of one command to another. They are the backbone of Bash one-liners and log analysis.

Common Operators

  • > – Write output to a file (overwrites)
  • >> – Append output to a file
  • < – Read input from a file
  • 2> – Redirect error messages
  • | – Pipe output into another command

ls -l > files.txt
echo "done" >> files.txt
cat log.txt | grep "error" | wc -l

Process Management Commands

These commands help you monitor running programs and stop the ones that misbehave, which is a daily task on servers.

Common Commands

  • ps – List running processes
  • top – Live view of CPU and memory usage
  • kill – Stop a process by PID
  • jobs, bg, fg – Manage background and foreground jobs

ps aux | grep nginx
kill 1234
sleep 60 &
jobs

Networking, Disk and Archive Commands

These commands are handy for checking connectivity, downloading files, monitoring storage and compressing data on servers.

Common Commands

  • ping – Test connectivity
  • curl – Send requests or download data
  • ssh / scp – Connect to and copy files to remote machines
  • df -h – Show disk space
  • du -sh – Show folder size
  • tar – Create or extract archives

ping -c 4 google.com
curl -O https://example.com/file.zip
df -h
tar -czvf backup.tar.gz projects/

Variables in Bash

Variables in Bash store data such as strings or numbers that can be reused in scripts or commands. They make scripts dynamic and flexible, allowing users to pass values and control program behavior.

Rules

  • No spaces around =
  • Access variables using $
  • Quote variables ("$name") to avoid errors with spaces
  • Use export to make a variable available to child processes

name="Sanjay"
echo $name

Special Variables

  • $0 – Script name
  • $1, $2 – Script arguments
  • $# – Number of arguments
  • $@ – All arguments
  • $? – Exit status of the last command

Read Also: Variables and Data Types in Go

Conditional Statements

Conditional statements allow Bash scripts to make decisions based on conditions. They are used to execute commands only when specific criteria are met such as checking file existence or comparing values.

Common Keywords

  • if
  • else
  • elif
  • fi

if [ -f file.txt ]
then
  echo "File exists"
else
  echo "File not found"
fi

Loops in Bash

Loops enable repeated execution of commands. They are useful for automating repetitive tasks such as processing multiple files or running checks at intervals.

Types of Loops

  • for
  • while
  • until

for i in 1 2 3
do
  echo $i
done

Functions in Bash

Functions let you group commands and reuse them in a script, which keeps larger scripts clean and easy to maintain.

greet() {
  echo "Hello, $1"
}
greet Sanjay

Bash Scripts

A Bash script is a file containing multiple Bash commands executed sequentially. Scripts help automate tasks, reduce manual work and ensure consistency in system operations.

Basic Script Structure

  • Starts with shebang #!/bin/bash
  • Contains executable commands

#!/bin/bash
echo "Hello, Bash!"

Bash Scripting Best Practices

  • Always start with #!/bin/bash
  • Make the script executable using chmod +x script.sh
  • Quote your variables to avoid errors with spaces
  • Use set -e to stop a script when a command fails
  • Test scripts with ShellCheck before using them in production

Useful Bash Shortcuts

Keyboard shortcuts improve productivity by reducing typing and speeding up command execution.

Common Shortcuts

  • Ctrl + C – Stop running command
  • Ctrl + Z – Pause command
  • Ctrl + L – Clear screen
  • Tab – Auto-complete

Read Also: Excel Keywords Shortcuts

Advanced Yet Useful Bash Commands

These advanced commands are commonly used for file searching, recursive log scanning, structured text extraction and bulk text replacement. They are especially helpful when working with large datasets, server logs or automation tasks.

find . -name "*.txt"
grep -r "error" .
awk '{print $1}' file.txt
sed 's/old/new/g' file.txt

Bash vs Shell vs Zsh: What's the Difference?

"Shell" is the general term for a command-line interpreter. Bash is one popular shell, and it is the default on most Linux distributions. Zsh is another shell, and it has been the default on macOS since Catalina. The basic commands in this Bash cheat sheet work in both, but some scripting syntax differs, so always check your shebang line.

Where Bash Is Used in Industry?

Bash is widely used in Linux-based servers, cloud platforms and DevOps environments. It is commonly used to automate deployments, manage Docker containers, configure servers and process log files. Many CI/CD tools execute Bash scripts during build and deployment stages. Because of this, Bash remains an essential skill for developers, system administrators and DevOps professionals.

Wrapping Up

Bash is a foundational skill for anyone working with Linux, cloud platforms or DevOps tools. Once you understand basic commands, file handling, permissions and scripting concepts, working in the terminal becomes much faster and more efficient.

This Bash cheat sheet covered the most commonly used features to help you build confidence without unnecessary complexity. Regular practice and small scripting exercises will strengthen your command over Bash and prepare you for real-world tasks as well as technical interviews. If you want to go beyond a cheat sheet, you can learn Bash scripting step by step with hands-on training.

Explore Our Trending Articles-

FAQs on Bash Cheat Sheet

Q1. Is Bash the same as Linux?

Bash is not Linux itself. Linux is an operating system and Bash is a shell that runs on Linux and allows users to interact with the system using commands. Bash acts as a bridge between the user and the operating system.

Q2. Do I need Bash if I use a GUI?

Learning Bash is useful even if you use a graphical interface. Many advanced tasks, server environments and automation workflows rely heavily on command-line operations where Bash is essential.

Q3. Is Bash scripting hard for beginners?

Bash scripting is beginner-friendly when learned step by step. Starting with basic commands, variables and conditions makes it easy to understand. Complexity increases only when you begin writing advanced automation scripts.

Q4. Where is Bash commonly used?

Bash is widely used in Linux systems, cloud servers, DevOps pipelines, system administration and automation scripts. It is also commonly used in CI/CD workflows and server maintenance tasks.

Q5. How long does it take to learn Bash basics?

Most beginners can learn Bash basics within a few days of regular practice. Mastering scripting and advanced usage may take a few weeks depending on hands-on experience.

Q6. Is it possible to damage the system using Bash commands?

Yes, certain commands like file deletion or permission changes can cause issues if used incorrectly. However, understanding commands before running them and avoiding system-level directories reduces risks significantly.

Q7. How do I check my Bash version?

Run bash --version in the terminal. It prints the installed version and license details.

Q8. What is the difference between Bash and Shell?

Shell is the general name for programs that interpret commands. Bash is a specific, widely used shell. Others include sh, zsh and ksh.

Q9. Can I use Bash on Windows?

Yes. You can use Bash on Windows through Windows Subsystem for Linux (WSL) or Git Bash.

Course Schedule
Course NameBatch TypeDetails
Bash Scripting Training
Every WeekdayView Details
Bash Scripting Training
Every WeekendView Details
About the Author
Jashan | igmGuru
About the Author

Jashan is a software developer with experience writing production code in multiple programming languages, with a focus on Python and R for data-intensive applications. Jashan's expertise includes automation scripting, data pipelines, debugging, and maintainable code practices. Apart from the developer part, he also writes well researched content to engage with learners.

Drop Us a Query
Fields marked * are mandatory
Recent Post
×

Your Shopping Cart


Your shopping cart is empty.