All tags
Start here · bash🐳Guide: Updating Docker Containers via the Unraid Terminal9 steps · 3 min read · Unraid users who update by handStart the guide bash
Narrow down
Guides1
Shell111
- Tip
echo {01..10}{01..10..2} in bash counts with zero padding and a stepBrace expansion can pad numbers with zeros and skip values with a step.3 Dec 2026 - Tip
shopt globskipdotsshopt globskipdots decides whether .* matches the . and .. entriesControls whether a pattern like .* also matches the current and parent folder entries.3 Dec 2026 - Tip
echo $EPOCHSECONDS$EPOCHSECONDS and $EPOCHREALTIME give you the time without calling dateTwo bash variables hold the current Unix time in seconds, or with microseconds.3 Dec 2026 - Tip
cmd > file 2>&1In bash, 2>&1 only follows where stdout points at that momentExplains why `cmd > file 2>&1` and `cmd 2>&1 > file` send errors to different places.3 Dec 2026 - Tip
export HISTIGNORE='ls*:pwd:cd*'HISTIGNORE keeps boring commands out of your bash historyLists command patterns that bash never saves in the history, like ls, pwd and exit.3 Dec 2026 - Tip
set -fset -f turns off globbing until you set +fSwitches off filename expansion in the current shell, so a * is passed on as a plain character.3 Dec 2026 - Tip
^[[1;5CCtrl-V shows the code a key really sends to your terminalShows the raw escape sequence of any key, which you need for key bindings.30 Nov 2026 - Tip
APP_HOST=example.com${!PREFIX@} lists every bash variable whose name starts the sameLoop over all settings like APP_PORT and APP_HOST without naming each one.30 Nov 2026 - Tip
set -eShopt -s inherit_errexit makes set -e work inside $( ) in bashStop a command substitution at the first failing line, like the rest of the script.30 Nov 2026 - Tip
cd /srv/app/releases || exit 1cd folder || exit stops a shell script that ends up in the wrong placeMake a script quit when cd fails, before it runs commands in the wrong folder.30 Nov 2026 - Tip
Ctrl-o # runs make, then shows the next history lineCtrl-o reruns a sequence of bash commands from your historyReplay a few commands in a row from history, one keypress each.30 Nov 2026 - Tip
source s.sh; echo "$PWD $X" # /tmp 1source runs a file in your current shell, ./script in a new oneKnow why cd and variables from a script vanish, and when source keeps them.30 Nov 2026 - Tip
a=(a b c d e)${arr[@]:1:2} takes a slice out of a bash arrayGet some elements of an array, like all but the first, without a loop.30 Nov 2026 - Tip
files=("my file.txt" notes.md)Quote "${files[@]}" so bash keeps names with spaces in one pieceExpand an array without breaking elements that contain spaces.30 Nov 2026 - Tip
GLOBIGNORE='*.bak:*~'GLOBIGNORE hides backup files from every shell wildcardKeep *.bak or *~ files out of every * you type in that session.30 Nov 2026 - Tip
exec > >(tee -a /var/log/nightly.log) 2>&1exec with tee logs everything a shell script printsSend all output of a script to a log file while you still see it on screen.30 Nov 2026 - Tip
red=$(tput setaf 1); green=$(tput setaf 2)Tput setaf colours script output in the terminal without hard coded escapesAdds colour to script messages in a way that stays quiet on dumb terminals.30 Nov 2026 - Tip
sleep $((RANDOM % 300))sleep $((RANDOM % 300)) spreads shell cron jobs over a few minutesAdd a random delay so many machines do not hit the same server at once.30 Nov 2026 - Tip
^ cursor on the i, press Ctrl-tCtrl-t swaps two letters you typed the wrong way round in the shellFix a typo like sl or sytemctl with one key instead of retyping.30 Nov 2026 - Tip
echo ./*./* protects shell commands from file names that start with a dashStop a file called -rf from being read as an option by rm or mv.30 Nov 2026 - Tip
set -xBASH_XTRACEFD sends set -x output of a bash script to its own fileKeep trace lines out of the normal error output of a script.30 Nov 2026 - Tip
bash -c 'exit -1'; echo $? # 255A shell exit code only goes up to 255, so exit 256 means successKeep exit codes between 0 and 255, because larger numbers wrap around.30 Nov 2026 - Tip
ls[0-9] and [!0-9] in a shell glob match one character from a setPick files by a digit or letter in a fixed spot, without regex.30 Nov 2026 - Tip
[[ -v b ]] && echo set || echo unset # set[[ -v name ]] tells bash whether a variable is set at allTell an unset variable apart from one that is set to an empty string.30 Nov 2026 - Tip
hosts=(web db cache)${!arr[@]} lists the indexes of a bash array, gaps and allLoop over positions or keys of an array, also after removing elements.30 Nov 2026 - Tip
declare -f mkcddeclare -f prints the code of a shell function you loaded earlierSee what a function in your shell really does, and where it came from.30 Nov 2026 - Tip
history -d 1042history -d removes a password you typed from bash historyDelete one line, or a range, from your history after typing something secret.30 Nov 2026 - Tip
wait "$db_pid"; db_status=$?wait PID gives you the exit code of one bash background jobRun jobs in parallel and still check which of them failed.30 Nov 2026 - Tip
Alt-b back one wordAlt-b and Alt-f move through a shell command one word at a timeJump over words on the command line instead of holding the arrow keys.30 Nov 2026 - Tip
EOFA quoted EOF stops the shell from expanding a here-documentWrite a script or config with dollar signs from a here-document, untouched.30 Nov 2026 - Tip
Alt-u UPPERCASE the rest of the wordAlt-u and Alt-l fix the case of a word on the shell lineChange a word to upper, lower or title case while you type a command.30 Nov 2026 - Tip
"\e[A": history-search-backwardThe Up arrow can search bash history for what you already typedType the start of a command, press Up, and get only matching history lines.30 Nov 2026 - Tip
set -e((i++)) stops a bash script under set -e when i is 0Avoid a counter that silently ends your script on its first increment.30 Nov 2026 - Tip
[x] Use Option as Meta keyUse Option as Meta key makes Alt shortcuts work in Mac TerminalLets the Option key act as Alt for word jumps and other shell shortcuts.30 Nov 2026 - Tip
echo '203.0.113.10 nas.example.com' | sudo tee -a /etc/hosts >/dev/nullSudo tee writes to a root-owned file where a shell redirect failsAppend a line to a file owned by root, because sudo echo > file fails.30 Nov 2026 - Tip
envsubst < site.conf.tpl > site.confenvsubst fills shell variables into a template fileTurn a config template with $VARIABLES into a real file without sed.30 Nov 2026 - Tip
key='abc123xyz'${#var} gives the length of a bash string or arrayCount characters or array items without wc or a loop.30 Nov 2026 - Tip
rm old-*.logCtrl-x * expands a wildcard on the bash line before you run itSee exactly which files a glob matches, and edit the list, before pressing Enter.30 Nov 2026 - Tip
echo "needs bash 4 or newer, this is $BASH_VERSION" >&2BASH_VERSINFO stops a script that needs a newer bash than macOS shipsFail early with a clear message when bash is too old for your script.30 Nov 2026 - Tip
select action in start stop status quit; doselect gives a bash script a numbered menu in a few linesLet a user pick an option by number without writing your own menu loop.30 Nov 2026 - Tip
v="a b"[[ ]] in bash does not split variables, where [ ] doesKnow why [[ ]] is safer in bash scripts and when you still need [ ].30 Nov 2026 - Tip
exec 3>>report.logexec 3> keeps a file open for the rest of a shell scriptOpen a log file once and write to it many times through a number.30 Nov 2026 - Tip
tmp=$(mktemp ./hosts.json.XXXXXX)Write to a temp file, then mv, so a shell script never leaves half a fileReplace a config or data file in one step, so readers never see it half written.30 Nov 2026 - Tip
IFS=, read -ra hosts <<< "$line"IFS=, read -ra splits a line into a shell arrayBreak a comma separated line into array elements without cut or awk.30 Nov 2026 - Tip
shopt -s nocaseglobshopt -s nocaseglob makes shell wildcards ignore upper and lower caseMatch photo.JPG and photo.jpg with one pattern.30 Nov 2026 - Tip
s=foo; s+=bar; echo "$s" # foobar+= appends to a bash string or array in placeAdd to a string or array without repeating the variable name on the right.30 Nov 2026 - Tip
shopt -s extglob*.@(jpg|png) matches several extensions in one shell globMatch a list of extensions without the empty results that braces leave.30 Nov 2026 - Tip
version=$(< VERSION)$(< file) reads a file into a shell variable without catLoad a small file into a variable without starting an extra cat process.30 Nov 2026 - Tip
compgen -c | sort -u | grep '^systemd-'compgen -c lists every command bash can run right nowSearch all commands, aliases and functions your bash knows about.30 Nov 2026 - Tip
local out=$(false)local x=$(cmd) hides a failed command in a shell functionDeclare and assign on separate lines so a failure inside $( ) is not lost.30 Nov 2026 - Tip
if [ -t 1 ]; then[ -t 1 ] tells a shell script whether a person is watchingUse colours and progress output only when output goes to a terminal.30 Nov 2026 - Tip
f() {"$@" passes every argument on to the next command, spaces and allForward the arguments of a script or function without breaking names with spaces.30 Nov 2026 - Tip
echo "main: $$ $BASHPID"$BASHPID gives the real PID in bash where $$ shows the parentGet the PID of the current subshell, where $$ still shows the parent.30 Nov 2026 - Tip
hash -r # forget everythinghash -r makes the shell forget where an old program livedFix 'No such file or directory' after moving or reinstalling a program.30 Nov 2026 - Tip
die() { echo "error: $*" >&2; stack >&2; exit 1; }FUNCNAME and BASH_LINENO print a stack trace from a bash scriptShow which chain of function calls led to an error in a longer script.30 Nov 2026 - Tip
set -o noclobberset -o noclobber stops > from overwriting existing filesBlocks the > operator from overwriting existing files unless you use >|.28 Nov 2026 - Tip
bash -n backup.sh && echo "syntax ok"bash -n checks a script for syntax errors without running itParses a script and reports syntax errors without executing a single command.28 Nov 2026 - Tip
shopt -s lastpipeshopt -s lastpipe keeps variables set inside a piped while loopRuns the last command of a pipeline in the current shell so its variables survive.28 Nov 2026 - Tip
source "$script_dir/config.env"BASH_SOURCE finds the folder a script lives inFinds the directory of the running script so it can load files next to it.28 Nov 2026 - Tip
printf -v stamp '%(%Y-%m-%d_%H%M)T' -1printf %(…)T puts today's date in a name without calling dateWrites the current date into a shell variable using only the printf builtin.28 Nov 2026 - Tip
read -r -s -p "Token: " token; echoread -s -p hides what you type, and -t gives up after a timeoutPrompts for input without echoing it and gives up after a set number of seconds.28 Nov 2026 - Tip
timeout 3 bash -c '</dev/tcp/192.168.1.x/443' && echo open || echo closedBash can test a TCP port through /dev/tcp without netcatChecks whether a TCP port accepts connections using only bash, no nc needed.28 Nov 2026 - Tip
disown -h %1disown lets a running job survive closing the terminalMarks a running background job so it keeps going after you close the shell.28 Nov 2026 - Tip
pushd /var/logpushd and popd give your shell a stack of folders to jump back toKeeps a numbered stack of folders so you can hop back and forth between them.28 Nov 2026 - Tip
PROMPT_COMMAND='history -a'PROMPT_COMMAND runs a command before every bash promptRuns a command of your choice before each prompt is shown.28 Nov 2026 - Tip
shopt -s dotglobshopt -s dotglob makes * match hidden files tooLets the * wildcard include files whose names start with a dot.28 Nov 2026 - Tip
shopt -s failglobshopt -s failglob makes bash refuse a wildcard that matches nothingMakes bash print an error and skip the command when a wildcard matches no files.28 Nov 2026 - Tip
type -a echotype -a lists everything a command name can mean in bashShows every alias, builtin, function and file behind a command name.28 Nov 2026 - Tip
false | true | falseBash PIPESTATUS shows which part of a pipeline failedReads the exit code of every command in the last pipeline, not only the final one.28 Nov 2026 - Tip
set -uset -u makes a script stop on a typo in a variable nameMakes bash exit with an error instead of treating an unset variable as empty.28 Nov 2026 - Tip
alias sudo='sudo 'alias sudo='sudo ' with a trailing space lets your aliases work after sudoMakes sudo ll and other aliases after sudo work instead of giving command not found.27 Nov 2026 - Tip
Ctrl-U # cut from the cursor to the start of the lineCtrl-U cuts the line you are typing and Ctrl-Y pastes it backParks a half-typed command so you can run another one first and paste it back.27 Nov 2026 - Tip
Ctrl-_ # undo the last editCtrl-_ undoes your last edit on the bash command lineTakes back your last change on the command line, one step per press.27 Nov 2026 - Tip
Ctrl-Z # pause the running commandCtrl-Z pauses a running command, bg sends it to the background and fg brings it backPauses a command that blocks your terminal and lets it continue in the background.27 Nov 2026 - Tip
local -n _list=$1local -n lets a bash function change an array you pass by namePasses an array to a bash function by name, so the function can change the original.27 Nov 2026 - Tip
declare -p appsdeclare -p shows exactly what is inside a bash variable or arrayPrints the type and exact quoted value of a bash variable, array or function.27 Nov 2026 - Tip
shopt -s histappendshopt -s histappend with history -a keeps bash history from every terminalSaves every command from every open terminal to your bash history instead of only the last one.27 Nov 2026 - Tip
shopt -s histverifyshopt -s histverify shows what !! or !$ expands to before bash runs itPuts the result of !! or !$ on your command line first, so you check it before it runs.27 Nov 2026 - Tip
set completion-ignore-case oncompletion-ignore-case in ~/.inputrc makes Tab completion ignore upper and lower caseLets Tab complete Documents when you type doc, and lists every match at once.27 Nov 2026 - Tip
count=10Local keeps a bash function from overwriting your variablesKeeps the variables of a bash function inside that function, so callers keep their values.27 Nov 2026 - Tip
f="my holiday photo.jpg"${var//old/new} replaces every match inside a bash variableSwaps text inside a bash variable, once or everywhere, without calling sed.27 Nov 2026 - Tip
PROMPT_DIRTRIM=2PROMPT_DIRTRIM=2 shortens a long path in your bash promptKeeps only the last few folders of the current path in your prompt.27 Nov 2026 - Tip
SECONDS=0The SECONDS variable tells a bash script how long it has been runningTimes a script or one step of it in bash without calling date.27 Nov 2026 - Tip
Alt-Ctrl-e # or press Esc, then Ctrl-eAlt-Ctrl-e expands variables, aliases and !! on the bash line before you press EnterShows on the prompt what a command becomes once bash fills in variables and aliases.27 Nov 2026 - Tip
shopt -s autocdshopt -s autocd lets you change folder by typing only its nameMoves into a folder when you type its name, without typing cd.27 Nov 2026 - Tip
for f in *.log; doShopt -s nullglob stops a for loop from running on a literal *.logMakes a bash glob that matches no files disappear, so loops skip instead of failing.27 Nov 2026 - Tip
Ctrl-x Ctrl-eCtrl-x Ctrl-e opens a long bash command in your editorOpens the command you are typing in your text editor and runs it when you save.27 Nov 2026 - Tip
export HISTTIMEFORMAT='%F %T 'HISTTIMEFORMAT adds a date and time to your bash historyShows the date and time next to every command in your bash history.27 Nov 2026 - Tip
set -xset -x with a better PS4 shows the line number of every traced commandShows the file and line number in front of every command bash traces with set -x.27 Nov 2026 - Tip
mkdir ~/projects/new-siteAlt+. pastes the last word of your previous commandInserts the last argument of the previous command at the cursor, and cycles back through older ones.24 Nov 2026 - Tip
make 2>&1 | lessUse |& to pipe stderr along with stdout in BashSends both normal output and error messages through the pipe, shorter than 2>&1.24 Oct 2026 - Tip
diffdiff <(cmd1) <(cmd2) compares output without temp filesCompares the output of two commands directly, without saving them to temporary files.10 Oct 2026 - Tip
cp /etc/ssh/sshd_config{,.bak}cp file{,.bak} makes a backup copy without typing the name twiceExpands to a command with the file name and a .bak copy, saving you from typing the path twice.26 Jul 2026 - Tip
shopt -s extglobWith extglob, !(*.log) matches everything except your log filesLists or selects every file except the ones matching a pattern, using Bash extended globs.18 Jul 2026 - Tip
shopt -s globstarshopt -s globstar lets ** match files in every subfolderTurns on ** in Bash so one pattern matches files in every subfolder.13 Jul 2026 - Tip
trap 'rm -rf "$tmp"' EXITtrap EXIT cleans up your temp files, even when the script diesRuns a cleanup command whenever the script exits, including after an error.4 Jul 2026 - Tip
rm -rf "${BUILD_DIR:?BUILD_DIR is not set}"/*${var:?} stops a script before an empty variable eats your filesStops the script with an error when a variable is empty, before a delete can hit the wrong path.24 Jun 2026 - Tip
set -o pipefailset -o pipefail makes a pipeline fail when any part of it failsMakes a pipeline report failure when any command in it fails, not only the last one.18 Jun 2026 - Tip
cd Alt+.Alt+. pastes the last argument of your previous commandPastes the last word of your previous command at the cursor, so you do not retype paths.9 Jun 2026 - Tip{ cmd1; cmd2; } > file redirects a whole shell group at onceSends the output of several commands to one file with a single redirect.7 Jun 2026
- Tip
sudo !!sudo !! reruns your last command with sudoReruns the previous command with sudo in front of it, so you do not retype it.2 Jun 2026 - Tip
wait -nwait -n continues a shell script when the first background job endsResumes the script as soon as any one background job has finished.2 Jun 2026 - Tip
sudo !!Type sudo !! when you forgot the sudoReruns your previous command with sudo in front, so you do not retype it.1 Jun 2026 - Tip
export CDPATH=.:~/dev:~/dev/workCDPATH lets cd jump to a folder from anywhere in your shellLets cd find folders by name in a list of parent directories.31 May 2026 - Tip
systemctl status ngnix^old^new reruns the last shell command with one word changedRepeats the previous command after fixing one word with a quick substitution.30 May 2026 - Tip
while getopts 'f:v' opt; doGetopts parses the flags of a shell script without extra toolsReads short command line flags in a script with a built-in parser.30 May 2026 - Tip
mapfile -t logs < <(find /var/log -name '*.log')mapfile -t loads command output into a shell array, one line per itemReads the lines of a command into a bash array without word splitting problems.30 May 2026 - Tip
f=/srv/media/holiday.final.mp4${file%.*} and ${file##*/} trim a shell variable without sedStrips an extension or a directory from a variable with built-in pattern removal.30 May 2026 - Tip
backup_dir=${BACKUP_DIR:-/var/backups}${var:-default} gives a shell variable a fallback, ${var:=x} also sets itUses a default value when a variable is unset or empty.30 May 2026 - Tip
while read -r line; do count=$((count+1)); done < <(ls /etc)while read with < <(cmd) keeps shell variables that a pipe losesKeeps variables set in a read loop by feeding it with process substitution.29 May 2026 - Tip
trap 'echo "failed at line $LINENO: $BASH_COMMAND" >&2' ERRtrap ERR with $LINENO tells you which line of a shell script failedPrints the line number and command when a bash script hits an error.15 Apr 2026
Storage8
- Tip
#rsync -av --delete /srv/media/ /mnt/backup/media/Alt-# comments out the bash line and saves it in historyPark a half-written command in history without running it.30 Nov 2026 - Tip
readonly BACKUP_DIR=/srv/backupreadonly keeps a shell script from changing an important path by accidentLock a variable after you set it, so later code cannot overwrite it.30 Nov 2026 - Tip
!rsync:p!cmd:p shows what bash would rerun without running itPreview a history expansion before you run it, then press Up to use it.30 Nov 2026 - Tip
time rsync -a /srv/data/ /mnt/backup/data/TIMEFORMAT makes the bash time keyword print one tidy lineGet a short, readable timing for any command or block in a script.30 Nov 2026 - Tip
f="backup-2026-11-27.tar.gz"${var:offset:length} cuts a piece out of a bash stringTakes a fixed part of a string in bash, counting from the start or the end.27 Nov 2026 - Tip
IFS=$'\t' read -r name size <<< $'backup.tar\t1048576'$'\t' puts a real tab or newline into a shell stringWrites tab and newline characters in a shell string with ANSI-C quoting.12 Jun 2026 - Tip
mkdir -p backup/{2025,2026}/{01..12}Brace expansion builds a folder tree in one shell commandCreates many folders at once by letting the shell expand braces.2 Jun 2026 - Tip
IFS=@ read -r user host <<< "jordi@nas"A here-string <<< feeds a variable to a command inside the shellGives a command a string as input without a pipe or a temporary file.30 May 2026
Network4
- Tip
prod_url=https://example.com${!name} reads a bash variable whose name is in another variablePick a setting like prod_url or test_url based on another variable.30 Nov 2026 - Tip
if ! diff -q /etc/nginx/nginx.conf /srv/backup/nginx.conf > /dev/null; thenDiff exits with 0, 1 or 2, and scripts can use thatUses diff's exit code to act only when a file really changed.30 Nov 2026 - Tip
declare -A port=(declare -A gives bash a lookup table with names as keysStores values under names in a bash script, so you can look them up by key.27 Nov 2026 - Tip
cd /var/log/nginxcd – takes you back to the last directorySwitches back to the directory you were in before the last cd.8 Jun 2026
Media2
- Tip
name=jellyfin${var^^} and ${var,,} change the case of a bash variableTurns a bash variable into upper or lower case without tr or awk.27 Nov 2026 - Tip
v="sonarr-4.0.10"[[ $s =~ regex ]] fills BASH_REMATCH with the parts that matchedMatches a regular expression in bash and gives you the captured parts without sed.27 Nov 2026
Docker1
Nothing matches.