← icestreams.io
ISS // TERMINAL
READY
Navigation
pwd print working directory ls list directory contents ls -la list with details + hidden cd <dir> change directory cd .. go up one level cd ~ go to home directory
Files
cat <file> display file contents touch <file> create empty file mkdir <dir> create directory cp src dst copy file mv src dst move or rename rm <file> remove file rm -r <dir> remove directory
Text
grep pat f search file for pattern head -n5 f first N lines tail -n5 f last N lines wc -l f count lines sort f sort lines cmd1 | cmd2 pipe output to command echo x > f write to file echo x >> fappend to file
Permissions
whoami current user id user and group IDs chmod +x f make executable chmod 644 f set octal permissions
Variables
X=value assign (no spaces!) echo $X expand variable echo "$X" quoted expansion (safe) ${X:-default} value or default if unset ${X:=val} assign if unset, then expand ${#X} string length of X ${X:2:4} substring offset 2 length 4 ${X//old/new} replace all occurrences ${X#pat} strip shortest prefix match ${X%pat} strip shortest suffix match ${X^^} uppercase X ${X,,} lowercase X readonly X=v make variable read-only declare -i N declare integer variable declare -r X declare read-only declare -x X export to environment export X export variable
Special Variables
$? exit status of last command $$ PID of current shell $0 script name $1 $2 … positional parameters $# number of arguments $@ all arguments (separate words) $* all arguments (one word)
Quoting
'literal' no expansion inside "double" variables/cmdsub expand inside $'c\tn' ANSI-C quoting (tabs, newlines) \char escape single character
Arithmetic
$(( 3 + 4 )) arithmetic expansion let N=5*2 arithmetic assignment expr 5 \* 2 external arithmetic $(( N++ )) post-increment $(( N % 3 )) modulo $(( N ** 2 )) exponentiation printf "%.2f" … floating point output
Tests & Conditions
[ -f file ] file exists and is regular [ -d dir ] directory exists [ -e path ] path exists (any type) [ -r f ] file is readable [ -x f ] file is executable [ -s f ] file non-empty [ -z "$X" ] string is empty [ -n "$X" ] string is non-empty [ "$a" = "$b" ] string equality [ "$a" != "$b"] string inequality [ $N -eq 0 ] numeric equal [ $N -lt 10 ] numeric less-than [ $N -ge 5 ] numeric greater-or-equal [[ $X =~ pat ]] regex match cmd1 && cmd2 run cmd2 only if cmd1 succeeds cmd1 || cmd2 run cmd2 only if cmd1 fails
Control Flow
if [ … ]; then
  cmds
elif [ … ]; then
  cmds
else
  cmds
fi
if / elif / else for x in a b c; do
  echo $x
done
for-in loop for (( i=0; i<5; i++ )); do
  echo $i
done
C-style for loop while [ cond ]; do
  cmds
done
while loop until [ cond ]; do
  cmds
done
until loop case $X in
 a) cmd;;
 b) cmd;;
 *) cmd;;
esac
case statement break exit loop continue skip to next iteration
Functions
greet() {
  echo "Hello $1"
}
define function greet "World" call function local X=val local variable (inside func) return 0 exit function with status
Arrays
A=(a b c) create array ${A[0]} first element ${A[@]} all elements ${#A[@]} array length A+=(d e) append elements for x in "${A[@]}"; do … iterate array
I/O & Redirection
cmd > file stdout to file (overwrite) cmd >> file stdout to file (append) cmd < file stdin from file cmd 2> err stderr to file cmd 2>&1 stderr → stdout cmd1 | cmd2 pipe stdout to stdin cmd | tee f stdout to file and screen cat << EOF
  text
EOF
here document
Command Substitution
$(command) capture command output X=$(date) assign output to variable echo "Today: $(date)" inline substitution
Text Tools
grep -n pat f show line numbers grep -v pat f invert match grep -c pat f count matching lines sed 's/a/b/g' f replace a→b globally sed '/pat/d' f delete matching lines awk '{print $2}' f print 2nd field awk '/pat/{print}' f print matching lines tr 'a-z' 'A-Z' translate chars sort -u sort and deduplicate sort -n numeric sort sort -rn reverse numeric sort uniq -c count occurrences cut -d: -f1 cut field 1 (colon delim) basename path filename from path dirname path directory from path printf "%s\n" x formatted output
Script Best Practices
#!/bin/bash shebang — always first line set -euo pipefail strict mode (exit on error) set -x trace / debug mode set +x disable trace # comment comment line exit 0 exit script with status trap 'cleanup' EXIT run on exit type cmd check what cmd resolves to source file.sh run file in current shell
Awk
awk '{print $1}' print first field of each line awk '{print $NF}' print last field awk '{print NR, $0}' print line number + line awk -F, '{print $2}' comma-separated (CSV) awk -F: '{print $1}' colon-separated (/etc/passwd) awk '/pattern/{print}' print matching lines awk '!/pat/{print}' print non-matching lines awk 'NR==3' print line 3 awk 'NR>1' skip header line awk '{sum+=$3} END{print sum}' sum a column awk '{count++} END{print count}' count lines awk 'BEGIN{FS=","}{print $1}' set FS in BEGIN block awk '/err/{c++} END{print c}' count matching lines
Make
make run default (first) target make all run "all" target explicitly make clean remove build artifacts make install install to system paths make test run test suite make -n dry run — show commands only make VAR=val override a Makefile variable
Makefile Syntax
VAR = value variable assignment $(VAR) expand variable target: deps
  <TAB>recipe
rule (tab required!) .PHONY: all clean declare non-file targets @echo text @ suppresses command echo $@ target name (automatic var) $< first prerequisite %.o: %.c pattern rule
Package Management
apt update refresh package index apt upgrade upgrade installed packages apt install pkg install package apt install -y pkg install without confirmation apt remove pkg remove package (keep config) apt purge pkg remove package + config apt search term search package names/desc apt show pkg show package details apt list --installed list installed packages dpkg -l low-level list of installed dpkg -s pkg package status + details dpkg -L pkg files installed by package
Environment & PATH
env show full environment echo $PATH show PATH value which cmd find binary for command type cmd alias/function/binary? export VAR=val set + export to environment export VAR export existing variable unset VAR remove variable export PATH="$HOME/bin:$PATH" prepend to PATH source ~/.bashrc reload shell config . ~/.bashrc same as source env | grep VAR find a specific variable
TIPS ↑/↓ history  ·  Tab completion  ·  Ctrl+L clear  ·  cat scripts/ to read examples
Progress 0 / 131
[ OBJECTIVE COMPLETE ]
i=insert  ·  Esc=normal  ·  :w=save  ·  :q=quit  ·  :wq=save+quit
-- NORMAL --
ISS // TERMINAL Sandboxed environment — no real system access © 2025 Ice Streams Systems