Tool.Yun
Handige tools voor ontwikkelaars
Achtergrond van de afbeelding verwijderen
Afbeelding EXIF/Metadata/GPS/JPEG Kwaliteitslezer
Afbeelding bijsnijden
Afbeelding naar SVG (potrace)
Afbeelding vergelijken
Afbeeldingsformaat wijzigen
Afbeeldingskleuromvormer
Camera recorder
Converter voor afbeeldingsformaten
EXIF verwijderen
GIF naar MP4
HEIC-converter
ICO/PNG-converter
OCR-afbeelding en PDF
SVG-voorbeeldweergave
Watermerk
Base64 Hex-array-encoder/-decoder
Base64 bestandconversie
Base64 string encoder/decoder
Basis converter
Converter voor veel eenheden
Csv naar gegevens
Dataopslageenheid converter
E-mailnormalisator
Eigenschappen converter
Energieverbruik- en kostencomputer
Env-variabelen formaatconverter
Excel naar gegevens
Omrekenaar van geografische coรถrdinaten
Romeins cijfer omzetten
Tekst naar UTF-8 binair
Tekst naar Unicode
Torrent naar Magneet
ULID-generator
Unicode-tekens naar Java-entiteiten converter
dBm mW-converter
AGE Cryptografie
Ansible kluis crypt decoderen
Argon2 Hasher
Bcrypt
Bech32 Encoder/Decoder
Bestand Hasher
CRC-calculator
Certificaat-/sleutelparser
ECDSA-sleutelpaargenerator
Ed25519 sleutelpaargenerator
HMAC generator
Hash-tekst
JWT-generator
JWT-parser
Jasypt String Encryption
MVO-generator
Niceware Bytes naar wachtwoordzin
PGP-bestandsversleuteling
PGP-encryptie
PGP-sleutelgenerator
Paseto/PASERK Lokaal
Paseto/PASERK Publiek/Privรฉ
RSA-encryptie
RSA-sleutelpaar generator
RSA/DSA/ECDSA-ondertekenaar en verificateur
SAML-parser
SSL-certificaatconverter
Shamirs geheime delen
Versleutel / ontsleutel tekst
X509-certificaatgenerator
BMI-calculator
BTW-nummervalidator
Compatibiliteit van softwarelicenties
Creditcardcontrole
IBAN validator en parser
IES-verlichtingsrichtlijnen
ISBN-validator en -parser
ISO 3166 Landcodezoeker
ISO 639-zoeker
Kalenderomzetter
Leg het shellcommando uit
Looptempo calculator
Luhn Validator
Online woordenboek
RMB Hoofdletterconverter
SLA-calculator
Telefoon parser en formatter
Unicode-zoekopdracht
Valutacalculator
Aftellen
Chronometer
Cron/Weekdag Alarm
Dagencalculator
Datum+Duurcalculator
Datum/tijd-converter
Duurcalculator
ETA calculator
ICAL-bestandsparser
ICAL-generator
TTL-calculator
Tijdalarm
Tijdzone-omzetter
Weeknummers converter
Welke dag?
iCal-fusie
Docker Compose Validator
Docker Compose naar .env-bestand
Docker Compose naar Docker run converter
Docker Compose naar Quadlets
Docker Compose-formaatconverter
Docker Pangolin-labels
Docker compose naar Kubernetes
Docker inspecteren om Docker uit te voeren
Docker run naar Docker compose converter
Docker run naar Kubernetes
Docker-image-downloader
Docker-run naar Quadlets
Dockerfile Label Generator
Kubernetes RBAC-generator
Traefik Docker Compose Maker
Amortisatiecalculator
ActiveDirectory LDAP-eigenschappenzoeker
Bestandstypedetector
Bounce e-mailparser
Converter voor drijvende-kommagetallen
Cookies-parser
DMARC-rapportanalysator
DNS-propagatietester
DNS-tester
Dode pixeltester
E-mailparser
EMV TLV-decoder
ETH-transactiedecoder
GZip/Deflate-converter
Gevoelige gegevensmasker
HTTPS-tester
Hex-encoder/decoder
Keycode-informatie
Korte URL's Expander
MIME-coderingsconverter
Midden-Endiaanse converter
MongoDB ObjectId-converter
Nmap Command Builder
Outlook MSG-parser
Outlook Safelink-decoder
Parketbestandenlezer
RJ45 Cat6 bedradingsspiekbrief
SMART Raw Converter
Seriรซle poortconsole
Sharepoint Share URL Decoder
Sneeuwvlok-ID-extractor
TCPDump-generator
Tekstcharsetdetector/-decoder
URL parser
URL-builder
Weerstandscalculator
้”ฎ็›˜ๆต‹่ฏ•ๅ™จ
Dobbelsteenroller
Kaartkiezer
Muntengooier
Rad van fortuin
BIP39 wachtwoordgenerator
Diceware wachtwoordgenerator
Generator voor willekeurige getallen
NanoIDs-generator
Numeroniem generator
OTP-codegenerator
Pincodegenerator
Token generator
UUID-converter
UUID-generator
Wachtwoordzingenerator
Berichtenpakket naar JSON
CSV naar JSON
JS naar JSON-converter
JSON naar .env
JSON naar C#
JSON naar CSV
JSON naar JS-converter
JSON naar Java Entiteit
JSON naar MessagePack
JSON naar TOML
JSON naar TS
JSON naar XML
JSON naar YAML converter
JSON naar gegevens
JSON om bezwaar te maken
JSON om te gaan
JSON opmaken en formatteren
JSON verkleinen
JSON-afvlakker/ontvlakker
JSON-diff
JSON-editor
JSON-fusie
JSON-linter
JSON-sorteermaster
Jq/JSONPath-tester
Json Escaper/Unescaper
Json naar PHP-Array
Json naar PHP-code
Json naar Python
Json naar SQL DDL
Json naar schema
Json-grootte-analysator
Json-query
Json-stringconverter
ObjGen naar JSON
PHP-Array naar JSON
tools.json-patch.name
Epub naar Markdown
HTML naar markdown
Markdown Lorem Ipsum
Markdown naar DOCX
Markdown naar HTML
Markdown naar data
Markdown naar tekst
Markdown-editor
Markdown-inhoudsopgavegenerator
Markdown-tabelgenerator
Markdown-tabelprettiger
Markdown-verschil
Markdown-voorbeeld
Plakken als Markdown
tools.markdown-format-converter.name
Beeldverhoudingcalculator
Benchmark-builder
Geo-afstandscalculator
Percentage calculator
Acceleratieomvormer
Drukeenheden converter
Energie-eenheden converter
Fitnesscomputer
Frequentieomzetter
Hoekeenheden converter
Kracht-eenheden converter
Lengte-eenheden converter
Massa-eenheden converter
Oppervlakte-eenheden converter
SI-voorvoegselomzetter
Snelheidsomzetter
Temperatuurconverter
Verlichtingssterkteconverter
Vermogenomvormer
Voedsel-energieomzetter
Volume-eenheden converter
Volumestroomomzetter
ARPA-decoder
Apache LogRotate Generator
BIMI DNS-generator
Basis-auth generator
Calculator voor het uitsluiten van IP-subnetten
Chmod calculator
Cloudflare DNS/RDAP-query's
Crontab generator
Curl Command Generator
DKIM DNS-generator
DMARC DNS-generator
DNS-query's
DNSBL-controleur
FStab-generator
Gegevensoverdrachtssnelheidcalculator
Gehele getallen naar IPv4/IPv6
Generator voor afsluitopdrachten
HAS-ontsmettingsmiddel
HDD-calculator
HTAccess-generator
Htpasswd/htaccess-generator
IP-geografische locatie
IPv4 subnetcalculator
IPv4-6/IPRange/CIDR in IP-bereik/CIDR/IP-masker
IPv4-adresconverter
IPv4-bereik uitbreider
IPv4-subnetlister
IPv4/6-bereik naar CIDR(s)-calculator
IPv6 ULA-generator
IPv6-adresconverter
IPv6-subnetcalculator
Iptables-generator
Ipv4/6 CIDR naar IP-bereikcalculator
MAC-adres generator
MAC-adres opzoeken
MAC-adresconverter
Microfoontester
Mijn IP-adres
Multilink-downloader
Nginx-formatter
Optie43 generator
PTR DNS-generator
Ping
Poortnummers
Punycode-converter
RAID-betrouwbaarheidscalculator
RAID-calculator
Rsync-generator
SIP-autorisatie
SPF DNS-generator
Shell-opdrachten formatteren
Shell-opdrachten linearisator
TCP/UDP-poorttester
UFW-commandogenerator
Visuele subnetcalculator
WPA PSK-generator
Wachtwoord sterkte-analyse
Websocket-testen
Whois-controle
Willekeurige poortgenerator
Wireguard-configuratiegenerator
X-VR-SpamCause Decoder
ZPOOL RAID-calculator
ZPool Spiekbriefje
Zxcvbn Wachtwoordsterkte
firewalld opdrachtregelgenerator
tools.restic-command-generator.name
tools.url-redirection-checker.name
ANSI Escape Tester
API-tests
Bestandssplitter
CSS/JS Opmaak & Minimalisatie
Cli-opdracht-editor
Code/Scripts Markeerstift
Database tabelgenerator
Database-creatiebuilder
Databaseverbindingsreeksbouwer
Django Secret Generator
Favicon-generator
Gegevensvervalser
GitIgnore-generator
Gitattributengenerator
HEX-bestandsconverter
Javascript Obfuscator
Javascript Prettifier
Javascript Unobfuscator/Unpacker
Json naar Protobuf
Json naar SQL INSERT
Json naar Typescript
K6 Load Testing Script Generator
Krulconverter
Mailto-generator
Offerte Converter
Open graph meta generator
Picomatch-tester
Pomodoro-timer
SQL opmaken en formatteren
SQL-minifier
SQL-parametergenerator
Stacktrace mooier
String Escaper
Swagger UI-tester
HTML naar PDF
PDF decoderen en ontgrendelen
PDF versleutelen
PDF-compressor
PDF-handtekening checker
PDF-pagina-extractor
PDF-tekstextractor
Pdf Lineariseren/FastWeb
Pdf-concatener
Algemene Regex-spiekbrief
Bash Spiekbriefje
CSS-selectors-spiekbriefje
Docker Compose-spiekbriefje
Docker SWARM-spiekbriefje
Docker-spiekbriefje
Dockerfile-spiekbriefje
Git Semantische Commit Spiekbriefje
Git cheatsheet
JSONPath-syntaxis-spiekbriefje
Jq Spiekbriefje
K8s Spiekbriefje
Markdown-spiekbriefje
Nano Spiekbriefje
Nginx Spiekbriefje
PowerShell-spiekbrief
Regex-spiekbriefje
Sed-spiekbriefje
Spiekbrief voor Zellij-commando's
Spiekbriefje voor Tmux-opdrachten
Spiekbriefje voor schermopdrachten
VIM-spiekbriefje
XPath-syntaxis-spiekbriefje
chmod Commando Spiekbriefje
Cron-expressiebouwer
Barcodegenerator
Barcodelezer
GTIN-validator
QR-code generator
QR-codedecoder
QR-contactgegevensgenerator
WiFi QR-code generator
tools.epc-qrcode-generator.name
TOML Linter
TOML naar JSON
TOML naar YAML
AI Prompt Splitter
ASCII-kunsttekstgenerator
Afbeelding naar ASCII Art
Bestanden inpakken voor AI
Citatiegenerator
Dubbele regelszoeker
Emoji keuze
GPT-token-encoder/-decoder
GPT-tokenschatter
Hoofdletter-omzetter
I en L-controleur
JSON naar TOON
Lettertype vergelijken
Levenshtein-rekenmachine
Lijstconverter
Lijsten vergelijken
Lorem ipsum generator
Mapstructuurdiagram
Morsecode-omzetter
RSVP-lezer
Regex-tester
Rune-converter
Sed Command-generator
Slimme tekstvervanger en regelafbreking
Sociale linkdeler
String obfuscator
TOON naar JSON
Tab naar Spaces
Tekst naar NAVO-alfabet
Tekst naar Unicode-namen
Tekst uit HTML halen
Tekst-diff
Tekststatistieken
Tekstvertaler
Toetsenbordindeling converter
Unicode naar GSM-7
Unicode-formatter
Verschillende woorden
Willekeurige regelkiezer
Zalgo Generator/Banner
Zeemeermin exporteur
Afbeelding naar CSS
Apparaat-informatie
CSS XPath-converter
CSS-eenhedenconverter
CSS-verloopgenerator
Css-prettiger
HTML WYSIWYG-editor
HTML naar XHTML
HTML naar data
HTML-entiteiten
HTML-minifier
HTML-prettiger
HTML-reiniger
HTTP-statuscodes
Kleurcontrastcontrole
Kleurconverter
Kleurenwiel
MIME-types
REM Pixelconverter
SVG placeholder generator
Slugify string
URL-catcher
URL-encoder
URL-reiniger
UTM-URL-generator
Url Tekst Zoeken Fragment Maker
User-agent parser
Binaire rekenmachine
Converter voor wiskundige formaten
Fooiencalculator
Trigonometrische/vergelijkingscurve-visualisator
Wiskunde evaluator
Wiskundige OCR
ObjGen naar HTML
XML formatter
XML naar JSON
XML-linter
XPath-tester
XSLT-tester
YAML naar JSON converter
YAML naar TOML
YAML opmaken en formatteren
YAML-afvlakker/ontvlakker
YAML-fusie

Bash Spiekbriefje

Veelvoorkomende Bash-opdrachten

Bash is the default shell on most Linux systems and the language of most glue scripts. This sheet covers the interactive shortcuts, the syntax you forget between scripts, and the safety flags worth putting at the top of every file.

#!/usr/bin/env bash
set -euo pipefail

โŒจ๏ธ Keyboard Shortcuts

KeysDoes
Ctrl+A / Ctrl+EJump to the start / end of the line
Ctrl+B / Ctrl+FBack / forward one character
Alt+B / Alt+FBack / forward one word
Ctrl+U / Ctrl+KCut to the start / end of the line
Ctrl+WCut the word before the cursor
Alt+DCut the word after the cursor
Ctrl+YPaste back what you last cut
Ctrl+T / Alt+TSwap the last two characters / words
Alt+.Insert the last argument of the previous command
Ctrl+LClear the screen
Ctrl+RSearch the history backwards
Ctrl+GAbort the history search
Ctrl+CInterrupt the running command
Ctrl+DEnd of input โ€” logs out of an empty prompt
Ctrl+ZSuspend the running command
Ctrl+S / Ctrl+QFreeze / resume terminal output
Alt+U / Alt+LUpper-case / lower-case to the end of the word

๐Ÿ•ฐ History

# the last few hundred commands
history

# run command number 42
!42

# run the last command again, or the last one starting with 'ssh'
!!
!ssh

# the last argument of the previous command โ€” also Alt+.
!$

# every argument of the previous command
!*

# re-run the last command with a substitution
^old^new

# forget a command you would rather not keep
history -d 42

# do not record commands that start with a space, and drop duplicates
export HISTCONTROL=ignoreboth
export HISTSIZE=10000 HISTFILESIZE=20000

๐Ÿ“ Files & Directories

# list: long, human sizes, hidden files, newest last
ls -lhAtr

# tree view of a directory
tree -L 2

# copy, move, delete
cp -r src/ dest/
mv old new
rm -rf directory

# create nested directories in one go
mkdir -p project/{src,test,docs}

# symbolic and hard links
ln -s /path/to/target linkname
ln target hardlink

# where is a file, and what is it?
find . -name '*.log' -mtime -7
find . -type f -size +100M
locate nginx.conf
which python3
type -a ls
file archive.bin
stat report.pdf

# disk usage: this directory, and the filesystem
du -sh *
du -h --max-depth=1 | sort -h
df -h

# archives
tar czf backup.tar.gz directory/
tar xzf backup.tar.gz
zip -r archive.zip directory/
unzip archive.zip

๐Ÿ”Ž Text & Search

# grep: recursive, line numbers, case-insensitive
grep -rni "pattern" .

# only the matching part, or only the file names
grep -o 'v[0-9.]*' file
grep -rl "TODO" src/

# invert, count, context
grep -v "debug" app.log
grep -c "error" app.log
grep -B2 -A2 "exception" app.log

# head, tail, follow
head -20 file
tail -f /var/log/syslog

# columns, sorting, counting
cut -d',' -f1,3 data.csv
sort -u names.txt
sort -k2 -n scores.txt
uniq -c sorted.txt
wc -l file

# the classic: what are the top ten IPs in this log?
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head

# replace across many files
sed -i 's/old/new/g' *.conf

# translate or delete characters
tr 'a-z' 'A-Z' < file
tr -d '\r' < dos.txt > unix.txt

# split a stream: to a file and onward down the pipe
command | tee output.log | grep error

# build command lines from input
find . -name '*.py' | xargs wc -l
find . -name '*.tmp' -print0 | xargs -0 rm

๐Ÿ–ง System & Network

# who and where am I
whoami; hostname; uname -a; uptime

# processes
ps aux | grep nginx
pgrep -a node
top
htop

# memory and load
free -h
vmstat 1 5

# what is listening, and what has this file open
ss -tulpn
lsof -i :8080
lsof /var/log/app.log

# connectivity
ping -c 4 example.com
traceroute example.com
dig example.com +short
ip addr show
curl -I https://example.com

# transfer files
scp file user@host:/path/
rsync -avz --progress src/ user@host:/dest/

# remote shell, with a tunnel
ssh user@host
ssh -L 8080:localhost:80 user@host

# services and logs (systemd)
systemctl status nginx
journalctl -u nginx -f --since "1 hour ago"

๐Ÿ“ฆ Variables

# assignment: no spaces around the =
name="value"

# only for this one command
DEBUG=1 ./script.sh

# export to child processes
export PATH="$HOME/bin:$PATH"

# read input from the user
read -p "Name: " name
read -rs -p "Password: " pass

# command substitution
today=$(date +%F)

# arithmetic
count=$(( count + 1 ))
let "n = 5 * 3"

# read-only and integer variables
declare -r VERSION=1.0
declare -i counter=0
VariableHolds
$0The name of the script
$1 โ€ฆ $9Positional arguments
$#How many arguments were passed
$@All arguments, each one quoted separately
$*All arguments as a single word
$?Exit status of the last command
$$PID of the current shell
$!PID of the last background job
$_Last argument of the previous command
$HOME $USER $PWD $OLDPWDThe usual environment
$RANDOMA random integer
$LINENOThe current line number โ€” handy in traps

๐Ÿ”ค Parameter Expansion

ExpansionResult
${var:-default}default when var is unset or empty
${var:=default}The same, and assigns it
${var:?message}Abort with message when unset โ€” great for required arguments
${var:+value}value only when var is set
${#var}The length of the value
${var:offset:length}A substring
${var#pattern}Strip the shortest match from the start
${var##pattern}Strip the longest match from the start โ€” ${path##*/} is basename
${var%pattern}Strip the shortest match from the end โ€” ${file%.txt} drops the extension
${var%%pattern}Strip the longest match from the end
${var/old/new}Replace the first match
${var//old/new}Replace every match
${var^^} / ${var,,}Upper-case / lower-case the whole value
path="/var/log/app.log"
echo "${path##*/}"    # app.log
echo "${path%/*}"     # /var/log
echo "${path%.log}"   # /var/log/app

๐Ÿ“š Arrays

# indexed arrays
fruits=(apple banana cherry)
fruits[3]="date"

echo "${fruits[1]}"       # banana
echo "${fruits[@]}"       # every element
echo "${#fruits[@]}"      # how many elements
echo "${!fruits[@]}"      # the indexes
echo "${fruits[@]:1:2}"   # a slice

for fruit in "${fruits[@]}"; do
  echo "$fruit"
done

# associative arrays (bash 4+)
declare -A color
color[apple]="red"
color[banana]="yellow"

echo "${color[apple]}"
for key in "${!color[@]}"; do
  echo "$key is ${color[$key]}"
done

๐Ÿงช Tests & Conditions

Use [[ ... ]] in bash โ€” it handles empty variables and patterns far better than the old [ ... ].

FilesTrue when
-e fileIt exists
-f fileIt exists and is a regular file
-d fileIt exists and is a directory
-L fileIt is a symbolic link
-s fileIt exists and is not empty
-r -w -xYou can read / write / execute it
-O fileYou own it
f1 -nt f2f1 is newer than f2 (-ot for older)
StringsTrue when
-z "$s"The string is empty
-n "$s"The string is not empty
"$a" == "$b"They are equal (= also works)
"$a" != "$b"They differ
"$a" < "$b"Sorts before, in the current locale
"$s" == pre*Glob match โ€” unquoted right-hand side
"$s" =~ ^re$Regex match, captures land in $BASH_REMATCH
NumbersMeaning
-eqEqual
-neNot equal
-ltLess than
-leLess than or equal
-gtGreater than
-geGreater than or equal
if [[ -f "$config" && -r "$config" ]]; then
  echo "readable"
elif [[ -d "$config" ]]; then
  echo "that is a directory"
else
  echo "missing"
fi

# arithmetic comparison reads more naturally in (( ))
if (( count > 10 )); then echo "plenty"; fi

๐Ÿ”€ Flow Control

# for over a list, a glob, or a range
for name in alice bob; do echo "$name"; done
for f in *.log; do gzip "$f"; done
for i in {1..10}; do echo "$i"; done
for (( i = 0; i < 10; i++ )); do echo "$i"; done

# while and until
while read -r line; do echo "$line"; done < input.txt
until ping -c1 host &>/dev/null; do sleep 5; done

# case
case "$1" in
  start)   echo "starting" ;;
  stop)    echo "stopping" ;;
  restart) echo "restarting" ;;
  *)       echo "usage: $0 {start|stop|restart}"; exit 1 ;;
esac

# select builds a numbered menu
select choice in build test deploy; do
  echo "you picked $choice"
  break
done

# loop control
continue   # skip to the next iteration
break      # leave the loop

๐Ÿงฐ Functions

greet() {
  local name="${1:?name required}"
  local greeting="${2:-Hello}"
  echo "$greeting, $name!"
  return 0
}

greet "World"
greet "World" "Good morning"

# capture the output, and check the status
message=$(greet "World")
if ! greet; then echo "greet failed"; fi

# make a function available to subshells
export -f greet

โžก๏ธ Redirection

SyntaxDoes
> fileSend stdout to a file, replacing it
>> fileAppend stdout to a file
2> fileSend stderr to a file
2>&1Send stderr wherever stdout is going
&> fileSend both to a file (bash)
> file 2>&1The portable form of the same
< fileRead stdin from a file
<<EOF โ€ฆ EOFHere-document
<<-EOF โ€ฆ EOFHere-document, leading tabs stripped
<<< "string"Here-string
|Pipe stdout into the next command
|&Pipe stdout and stderr
> /dev/null 2>&1Discard everything
<(command)Process substitution โ€” a command as a file
tee fileWrite to a file and pass the stream on
# a heredoc, expanded
cat <<EOF > config.ini
host=$HOSTNAME
port=8080
EOF

# a heredoc, literal (quoted delimiter)
cat <<'EOF' > script.sh
echo "$HOME is not expanded here"
EOF

# compare the output of two commands without temporary files
diff <(sort a.txt) <(sort b.txt)

โš™๏ธ Jobs & Processes

# run in the background, and list the jobs
long_task &
jobs

# bring back to the foreground, or resume in the background
fg %1
bg %1

# Ctrl+Z suspends the foreground job

# survive logout
nohup ./script.sh > out.log 2>&1 &
disown -h %1

# wait for background jobs
wait
wait $!

# signals
kill 1234
kill -9 1234
kill -TERM %1
pkill -f "node server.js"

# give a command a deadline
timeout 30s ./slow_task.sh

# clean up on exit, whatever happens
trap 'rm -f "$tmpfile"' EXIT
trap 'echo interrupted; exit 130' INT TERM

๐Ÿ›ก Safe Scripting

#!/usr/bin/env bash
# -e  exit on any failing command
# -u  treat unset variables as an error
# -o pipefail  a pipeline fails if any stage fails
set -euo pipefail

# make word splitting predictable
IFS=$'\n\t'

# always quote expansions
cp "$src" "$dest"

# check the syntax without running anything
bash -n script.sh

# trace every command as it runs
bash -x script.sh
set -x; risky_command; set +x

# a more informative trace prefix
export PS4='+ ${BASH_SOURCE}:${LINENO}: '

# report where a script died
trap 'echo "failed at line $LINENO with status $?" >&2' ERR

# and lint it before it reaches anyone else
shellcheck script.sh

โš ๏ธ set -e has surprising corners: it does not fire inside if, &&, || or command substitutions used in assignments. It is a seatbelt, not autopilot โ€” still check what matters explicitly.

๐ŸŽจ Colours

Escape sequences take the form \033[<style>;<colour>m, and \033[0m resets. \e and \x1B are the same character as \033.

ColourForegroundBrightBackground
Black309040
Red319141
Green329242
Yellow339343
Blue349444
Magenta359545
Cyan369646
White379747
StyleCodeStyleCode
Reset0Underline4
Bold1Blink5
Dim2Reverse7
RED='\033[0;31m'
GREEN='\033[0;32m'
BOLD='\033[1m'
RESET='\033[0m'

echo -e "${GREEN}ok${RESET} โ€” ${RED}${BOLD}failed${RESET}"

# only colourise when stdout is a terminal
if [[ -t 1 ]]; then RED='\033[0;31m'; RESET='\033[0m'; else RED=''; RESET=''; fi

๐Ÿ’ก Tips

# aliases and functions belong in ~/.bashrc
alias ll='ls -lhA'
alias gs='git status -sb'
mkcd() { mkdir -p "$1" && cd "$1"; }

# reload the config after editing it
source ~/.bashrc

# brace expansion saves a lot of typing
cp config.yaml{,.bak}
mkdir -p src/{components,utils,tests}

# repeat the previous command as root
sudo !!

# go back to the previous directory
cd -

# run something regardless of the current directory
(cd /tmp && ./task.sh)

# time a command, and keep a transcript of a session
time ./build.sh
script session.log

๐Ÿ“š Resources

  • GNU Bash manual
  • ShellCheck โ€” lints your scripts
  • Bash Pitfalls
  • Google Shell Style Guide
  • explainshell โ€” break down any command line