Core commands
# list files
ls -al
# print the path
pwd
# change directory
cd project
# show the first lines of a file
head -n 20 README.md
# search text in files
grep -R "pattern" src/
A concise guide for students and makers. Understand the shell, run commands with confidence and write small scripts that save time.
Bash reads input, runs programs and connects them with pipes. It keeps a history and supports completion. It can act as an interactive tool or as a language for scripts. Most Linux distributions ship it as a default login shell. It is also present on macOS and can run on Windows through WSL or Git Bash.
# list files
ls -al
# print the path
pwd
# change directory
cd project
# show the first lines of a file
head -n 20 README.md
# search text in files
grep -R "pattern" src/
# pass output of one program to another
ps aux | grep python
# save output to a file
make build > build.log 2>&1
# append to a log
echo "done" >> build.log
#!/usr/bin/env bash
set -Eeuo pipefail
IFS=$'\n\t'
main(){
local name=${1:-world}
echo "hello $name"
}
main "$@"
name="Alice"
echo "Hi $name"
for f in *.txt; do
wc -l "$f"
done
Open a terminal and run bash --version. On Linux it is already installed. On macOS it ships with the system and you can install a newer build with your package manager. On Windows you can enable WSL or install Git for Windows which includes Git Bash.
Read the manual with man bash. Explore the Bash Reference Manual. Practice with small scripts. Use shellcheck to catch common issues and quote variables to avoid word splitting. Prefer long options when available so scripts are easier to read.
Bash is compatible with the older sh and adds many features. When writing portable scripts target POSIX sh or run in Bash with POSIX mode.
Yes on Unix like systems you can use the chsh command to pick a shell. You need a valid entry in the list of allowed shells.
Use the official project channels. Include your version and a small script that reproduces the issue.
Free resources from Clipart Library