Skip to main content

Bash

Explore Bash scripting to automate everyday tasks. Learn command-line techniques, shell utilities, and tips for building robust scripts.

8posts

Guides

Posts

Bash
|5 min read

Using ls to list directories and their total sizes

How to show directory sizes from the shell - practical commands for macOS and Linux, and why `ls` alone is not enough.

Bash
|6 min read

How to Sleep for Milliseconds in Bash and Linux

Learn how to pause script execution for fractions of a second using sleep, usleep, and other methods for precise timing in Bash scripts and command-line operations.

Bash
|15 min read

What Does set -e Mean in Bash? Shebangs, sh vs bash and the Script Directory

The first lines of a Bash script decide which shell runs it, what happens when a command fails and where it finds its files. Learn what set -euo pipefail does and where it does not stop a script, which shebang to use, how sh differs from bash, and how to get the script directory.

Bash
|7 min read

How Does cat << EOF Work in Bash?

Understand heredocs in Bash - the << EOF syntax that lets you write multi-line strings, create files with embedded content, and pass complex input to commands.

Bash
|7 min read

How to Prompt for Yes/No/Cancel Input in a Linux Shell Script

Learn different techniques for creating interactive prompts in your shell scripts, from simple yes/no confirmations to three-way choices with proper input validation and user-friendly interfaces.

Bash
|16 min read

What Does "2>&1" Mean in Linux and Bash?

Learn what the 2>&1 redirection operator means, how stdout and stderr work, and how to send all output to a file, to the screen and a file with tee, to a protected file with sudo, or only to stderr.

Bash
|11 min read

How to Loop Through File Lines, Arrays and Number Ranges in Bash

Read a file line by line without losing spaces or backslashes, keep variables set inside the loop, loop safely over file names, iterate over arrays, and loop over a number range stored in variables.