Skip to main content

Bash

Browse all articles, tutorials, and guides about Bash

17posts

Guides

Posts

DevOps
|12 min read

Base64 Explained: 3 Bytes In, 4 Characters Out, Zero Secrecy

Base64 turns 3 bytes into 4 characters and hides nothing. See it in Kubernetes Secrets and JWTs, measure the 33% overhead, and fix the bugs it causes.

Linux
|13 min read

Ubuntu 26.10 Moves cp, mv and rm to Rust. We Ran 162 Shell Commands Through GNU and uutils to See What Changes

Ubuntu 26.10 ships on October 15 with Rust coreutils for every tool. On the same system, 150 of our 162 shell test cases gave byte-identical results with GNU and uutils. The other 12 come down to four changes that can break a script (GNU detection, cut -c, timeout -s KILL, base64 -d) and five error messages.

Linux
|11 min read

How to Get the Current Date, Time and Epoch Seconds in Linux and Bash

Print and format the current date and time with date, get Unix epoch seconds and milliseconds, convert between dates and timestamps, measure how long a command takes, and turn your favorite format into a custom command.

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.

Linux
|21 min read

How to Find Files Using Wildcards in Linux, Exclude Directories and Count Files

Use find with wildcards to search directory trees, fix "Argument list too long", skip directories such as node_modules in find and tar, count files and lines of code, and change permissions for folders and files separately.

Linux
|13 min read

How to Permanently Set $PATH on Linux and Unix

Learn how to permanently modify your PATH environment variable on Linux and Unix systems so your custom directories persist across shell sessions and reboots, then reload .bashrc, export or delete variables, and write aliases that take parameters.

Linux
|9 min read

How to Copy Command Output Directly to Your Clipboard in Linux

Pipe command output to the clipboard with wl-copy on Wayland, xclip or xsel on X11, pbcopy on macOS and clip.exe on WSL. Paste it back, write clipboard functions for scripts, and copy to your local clipboard over SSH.

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.

Linux
|11 min read

How to Parse and Check Command Line Arguments in Bash

Read positional arguments with $1 and "$@", check that the user passed the arguments a script needs, parse short options with getopts and long options such as --env=prod with a while loop.

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.

Linux
|9 min read

How to Change the Output Color of Echo and Fix Newlines in Bash

Print colored text in a Linux terminal with ANSI escape codes or tput, turn colors off when output is not a terminal, and fix echo when it prints a literal \n instead of a new line.

Linux
|13 min read

How to Check if a File, Directory, Variable or Command Exists in Bash

The Bash tests you use in almost every script: check if a directory or file exists, if a variable is set or empty, if a string contains a substring, how to compare text without case, and if a program is installed.

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.