← All insightsCheat Sheet

Bash & Shell Scripting cheat sheet: the complete command reference

CodeWizard Engineering · 22 January 2026 · 3 min read · Beginner

This is a complete, hands-on Bash & Shell Scripting cheat sheet: install, configure, operate, automate and secure it - with copy-paste commands grouped by task. Bookmark it for day-to-day work, incidents and interviews alike.

Bash is the shell present on virtually every Linux system. With strict mode and a little discipline it is perfect for small, reliable automation, wrappers and glue between tools.

Why you reach for it

  • Available everywhere - no runtime to install
  • Perfect for gluing CLIs and small automation tasks
  • Fast feedback loop for operational one-liners

Installation

bash
bash --version
# lint your scripts
brew install shellcheck shfmt || sudo apt-get install -y shellcheck

Configuration reference

A safe script skeleton with strict mode and a trap.

bash
#!/usr/bin/env bash
set -Eeuo pipefail
trap 'echo "error on line $LINENO" >&2' ERR

main() {
  local name="${1:?usage: deploy <name>}"
  echo "deploying ${name}"
}
main "$@"

Core commands you use daily

bash
shellcheck deploy.sh
shfmt -d -i 2 deploy.sh
bash -n deploy.sh   # syntax check without running

Safe defaults & parameters

bash
set -Eeuo pipefail
name="${1:?usage: deploy <name>}"     # required arg
env="${ENV:-prod}"                     # default value
files=(*.log)                          # array
for f in "${files[@]}"; do echo "$f"; done

Text processing

bash
grep -R --line-number 'ERROR' logs/
sed -i 's/old/new/g' file.txt
awk -F, '{ sum += $2 } END { print sum }' data.csv
find . -name '*.tmp' -mtime +7 -delete

Use it in CI/CD

Lint shell scripts in CI.

yaml
- uses: ludeeus/action-shellcheck@master
- run: shfmt -d -i 2 .

Best-practice checklist

  • Start every script with set -Eeuo pipefail and an ERR trap
  • Quote all variable expansions; prefer [[ ]] over [ ]
  • Run shellcheck and shfmt in CI

Common pitfalls to avoid

  • No set -euo pipefail, so failures are silently ignored
  • Unquoted variables that break on spaces and globs
  • Parsing ls output or using eval on untrusted input

Security quick wins

  • Never eval untrusted input; validate arguments
  • Keep secrets in the environment, not in argv (visible in ps)

Works well with

  • Python for DevOps - The glue language of DevOps - automation scripts, CLIs, API clients and operators.
  • linux
  • Ansible - Agentless configuration management and provisioning over plain SSH, described in readable YAML.
A cheat sheet is muscle memory on paper - keep it close until the commands live in your fingers.

Want senior help putting Bash & Shell Scripting to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult