Bash Essentials

Shell scripting fundamentals and the everyday utilities that make the command line a dev superpower.

35 flashcards · select reveal or click a card to see details

basics beginner

Variables

Assign without spaces around =; reference with $.
basics beginner

Prompt

The prompt is the text Bash shows when it is ready for your next command.
basics beginner

Quoting

Single quotes preserve everything literally; double quotes allow variable expansion.
basics beginner

echo & printf

echo for simple output, printf when you need formatting or precise control.
navigation beginner

pwd

pwd prints the current working directory.
navigation beginner

cd

cd changes the current directory.
basics beginner

Command Substitution

Capture the output of a command into a variable.
basics beginner

Exit Codes

Every command returns 0 (success) or non-zero (failure). Available as $?.
navigation beginner

ls

ls lists files and directories.
basics beginner

Shebang & Permissions

The shebang line tells the OS which interpreter to use; the file must be executable.
control-flow beginner

if / else

Conditional execution. Test expressions go in [[ ... ]].
commands beginner

cat and less

cat concatenates and prints file contents to the terminal; less opens a paged, scrollable view of a file.
control-flow beginner

for loops

Iterate over a list, range, or files matching a glob.
files beginner

touch and mkdir

touch updates a file’s timestamp, or creates it empty if it does not exist; mkdir creates a directory.
control-flow beginner

while loops

Repeat while a condition holds. Most useful for reading input line-by-line and polling.
control-flow beginner

case

Match a value against multiple patterns. Cleaner than long if/elif chains.
files beginner

cp, mv, and rm

cp copies, mv moves or renames, and rm removes files.
files-streams beginner

Redirection

Send command output to a file or read input from a file.
files-streams beginner

Pipes

Connect the stdout of one command to the stdin of the next.
files-streams beginner

File Tests

Common tests inside [[ ]] for checking file properties.
files-streams beginner

stdin / stdout / stderr

File descriptors 0, 1, 2: input, normal output, error output.
files-streams beginner

Globs & Wildcards

Pattern matching for filenames.
utilities beginner

grep

Search for patterns in files or stdin.
utilities beginner

find

Locate files by name, type, modification time, or other attributes.
scripting intermediate

Environment variables

Environment variables are shell variables marked with export, so child processes inherit them.
utilities beginner

sed

Stream editor for find/replace and basic transforms on text.
utilities beginner

awk

Column-oriented text processing, powerful for tabular data.
utilities beginner

xargs

Build commands from stdin, useful for chaining find to other commands.
utilities beginner

jq

Like sed/awk for JSON. Essential for working with APIs and structured logs.
workflows intermediate

Robust Script Template

A safe starting point for any new script. The set options catch errors that would otherwise pass silently.
workflows intermediate

Process Files in a Loop

A common pattern: iterate over matching files and run something on each, with proper handling of edge cases like spaces and nested directories.
workflows intermediate

Args & User Input

Standard pattern for parsing positional args and flags in a script.
workflows intermediate

Background Jobs

Run commands asynchronously and manage long-running processes.
workflows intermediate

Cron / Scheduled Tasks

Run scripts on a schedule. Cron is the standard Unix scheduler and is everywhere.
scripting intermediate

Functions

A Bash function names a reusable group of commands.