Skip to content
Hands-on IT IT Drills

Day 6: Modern CLI tools

Goal: Replace the classic Unix tools in everyday work with faster, more readable successors, without unlearning the classics. · Duration: approx. 75 min · Prerequisite: Day 5

Briefing

  • The new tools are defaults for humans: color, .gitignore awareness, sensible presets.
  • The classics (grep, find, cat, ls, diff, top, man, curl) remain mandatory. They’re available on every server, in every container and in every script.
  • Rule of thumb: interactively new, in scripts classic.
  • All tools come from the Brewfile (Day 0). Check: brew bundle check --file=Brewfile.
grep -> rg      find -> fd      cat  -> bat     ls  -> eza
cd   -> z       sed/awk on JSON/YAML -> jq/yq   diff -> delta
top  -> btop    man  -> tldr    curl -> http (httpie)

Drill 1: ripgrep instead of grep

cd ~/term-lab/projekt
grep -rn TODO . | wc -l
rg TODO

Expected (order may vary):

       7
scripts/report.py
13:# TODO: als JSON ausgeben

internal/cart/cart.go
16: // TODO: Rabatte berücksichtigen

cmd/shop/main.go
13:     port = "8080" // TODO: aus config/app.yaml lesen

grep finds seven matches, four of them in .git/hooks/*.sample. rg skips .git, hidden files and everything from .gitignore. That applies to logs/ too:

rg -c ERROR; echo "rc=$?"
rg -uu -c ERROR
rg -c ERROR logs

Expected:

rc=1
logs/app.log:50
logs/app.log:50

-u lifts .gitignore, -uu additionally “hidden”. If you give the path explicitly, rg always searches there.

The options you need every day:

rg -t go -w port                    # Go files only, whole word
rg -l TODO                          # file names only
rg -C1 -t py TODO                   # 1 line of context
rg -o -N 'user=u\d+' logs/app.log | sort | uniq -c | sort -rn | head -3

Expected (shortened):

cmd/shop/main.go
11: port := os.Getenv("PORT")
12: if port == "" {
...
scripts/report.py
12-            counts[parts[2]] += 1
13:# TODO: als JSON ausgeben
14-for level, n in counts.most_common():
  22 user=u16
  22 user=u15
  22 user=u14

How much faster? A large folder, five runs:

cd /opt/homebrew/Library/Homebrew
hyperfine -N -w 1 -r 5 'grep -rn TODO .' 'rg -n TODO .'
cd ~/term-lab/projekt

Expected (shortened, depends on your Mac):

Benchmark 1: grep -rn TODO . (5 runs)
  Wall Time    803.3 ms  ±    82.5 ms     743.2 ms  …   944.9 ms
Benchmark 2: rg -n TODO . (5 runs)
  Wall Time     25.7 ms  ±     1.3 ms      24.2 ms  …    27.3 ms  -96.8%  (31.3x faster)

The comparison isn’t entirely fair: rg runs in parallel and leaves out ignored files. But that’s exactly what you almost always want interactively.

Your own default options go in a file that RIPGREP_CONFIG_PATH points to:

cat > ~/term-lab/config/ripgreprc <<'EOF'
# ripgreprc – one option per line (Day 6)
--smart-case
--hidden
--glob=!.git/
--max-columns=150
--max-columns-preview
EOF
export RIPGREP_CONFIG_PATH=~/term-lab/config/ripgreprc
rg todo --sort path | head -2

Expected:

cmd/shop/main.go
13:     port = "8080" // TODO: aus config/app.yaml lesen

--smart-case: in lowercase it searches case-insensitively; as soon as an uppercase letter appears, exactly. --sort path makes the output stable, but costs the parallelism.

Save your progress? Sign up for free

Drill 2: fd instead of find

find . -name '*.go'
fd -e go
fd yaml
fd -t d

Expected:

./cmd/shop/main.go
./internal/cart/cart.go
cmd/shop/main.go
internal/cart/cart.go
config/app.yaml
deploy/k8s/deployment.yaml
cmd/
cmd/shop/
config/
deploy/
deploy/k8s/
docs/
internal/
internal/cart/
scripts/

fd yaml searches by regex in the file name, without -name '*…*'. Like rg, fd ignores hidden and ignored files:

fd -e log; echo "rc=$?"
fd -u -e log
fd -H gitignore

Expected:

rc=0
logs/access.log
logs/app.log
.gitignore

Watch out: even without matches, fd returns exit code 0. In scripts, you count the lines.

Running commands on matches: -x once per file (in parallel), -X once with all files:

fd -e go -x wc -l
fd -e yaml -X bat --style=header -r 1:2

Expected (order may vary with -x):

      18 ./internal/cart/cart.go
      20 ./cmd/shop/main.go
File: ./deploy/k8s/deployment.yaml
apiVersion: apps/v1
kind: Deployment

File: ./config/app.yaml
service: shop
port: 8080

Save your progress? Sign up for free

Drill 3: bat instead of cat

bat -r 10:14 cmd/shop/main.go

Expected:

─────┬──────────────────────────────────────────────────────
     │ File: cmd/shop/main.go
─────┼──────────────────────────────────────────────────────
  10 │ func main() {
  11 │     port := os.Getenv("PORT")
  12 │     if port == "" {
  13 │         port = "8080" // TODO: aus config/app.yaml lesen
  14 │     }
─────┴──────────────────────────────────────────────────────

In the terminal this is in color. bat knows Git: changed lines get a marker.

echo "  x" >> README.md
bat --style=changes,numbers -r 8:10 README.md
git restore README.md

Expected:

   8   - `deploy/k8s` – Manifeste
   9 +   x

Make invisible characters (tabs, trailing spaces) visible:

printf 'a\tb \n' | bat -A

Expected (shortened):

   1 │ a├─┤b·␊

├─┤ is a tab, · a space, ␊ the end of line. Ideal for broken YAML indentation.

Tip: In a pipe, bat behaves like cat: no frames, no colors. So an alias cat=bat doesn’t break pipes. Your head still has to remember that on servers it’s cat waiting for you.

Save your progress? Sign up for free

Drill 4: eza instead of ls

eza -l --git --group-directories-first

Expected (shortened):

drwxr-xr-x@   - du 10 Okt 08:35 -- cmd
drwxr-xr-x@   - du 10 Okt 08:35 -- config
drwxr-xr-x@   - du 10 Okt 08:35 -I logs
drwxr-xr-x@   - du 10 Okt 08:35 -- scripts
.rw-r--r--@  33 du 10 Okt 08:35 -- go.mod
.rw-r--r--@ 260 du 10 Okt 08:35 -- README.md

The Git column shows the status: -- unchanged, -M modified, -I ignored, -N new.

eza --tree --level=2 --git-ignore

Expected (shortened):

.
├── cmd
│   └── shop
├── config
│   ├── app.json
│   └── app.yaml
├── deploy
│   └── k8s
├── docs
│   └── notizen.txt
...

Now the matching aliases. They only apply if the tool is installed. That way the configuration stays usable on a Mac without eza:

cat >> ~/term-lab/config/zsh/aliases.zsh <<'EOF'

# Modern tools (Day 6), only if installed
if (( $+commands[eza] )); then
  alias ls='eza --group-directories-first'
  alias ll='eza -l --git --group-directories-first --time-style=relative'
  alias la='eza -la --git --group-directories-first'
  alias lt='eza --tree --level=2 --git-ignore'
fi
(( $+commands[bat] )) && alias cat='bat --paging=never --style=plain'
EOF
reload
ll go.mod

Expected:

.rw-r--r--@ 33 du 6 minutes -- go.mod

The relative time depends on when you did Day 0.

Save your progress? Sign up for free

Drill 5: zoxide instead of cd

zoxide remembers where you jump often and recently (frecency). After that, part of a word is enough. You put the database in the lab so that a real zoxide database stays untouched:

cat > ~/term-lab/config/zsh/tools.zsh <<'EOF'
# tools.zsh – initialization of modern tools (Day 6)

# zoxide: database in the lab, so the real one (if any) stays untouched
if (( $+commands[zoxide] )); then
  export _ZO_DATA_DIR="$LAB/zoxide"
  mkdir -p "$_ZO_DATA_DIR"
  eval "$(zoxide init zsh)"
fi

# bat as the pager for man pages (with syntax highlighting)
if (( $+commands[bat] )); then
  export MANPAGER="sh -c 'col -bx | bat -l man -p'"
  export MANROFFOPT="-c"
fi

# ripgrep: own options in a file
export RIPGREP_CONFIG_PATH="$LAB/config/ripgreprc"
EOF
reload
cd internal/cart; cd ~/term-lab/projekt/deploy/k8s; cd /tmp
z cart && pwd
z k8s && pwd
zoxide query -ls

Expected (shortened):

/Users/du/term-lab/projekt/internal/cart
/Users/du/term-lab/projekt/deploy/k8s
   8.0 /Users/du/term-lab/projekt/internal/cart
   8.0 /Users/du/term-lab/projekt/deploy/k8s
   4.0 /tmp

zi opens an interactive picker with fzf (Day 7). tools.zsh and ripgreprc are also in $BUCH/zsh/. z - jumps back like cd -. zoxide doesn’t record the home directory.

Warning: zoxide init belongs at the end of the configuration, because it sets a hook on cd. That’s satisfied here: the lab .zshrc loads config/zsh/*.zsh last.

Save your progress? Sign up for free

Drill 6: jq and yq instead of grep on structures

grep sees text, jq sees JSON:

grep -o '"replicas":[0-9]*' config/app.json
jq -r '.service, .replicas' config/app.json
jq .features config/app.json
jq -c '{service, an: [.features | to_entries[] | select(.value) | .key]}' \
  config/app.json

Expected:

"replicas":3
shop
3
{
  "rabatt": false,
  "newsletter": true
}
{"service":"shop","an":["newsletter"]}

yq (by Mike Farah) speaks the same language for YAML. Anyone who touches Kubernetes manifests needs it:

yq .database.host config/app.yaml
yq '.spec.template.spec.containers[0].image' deploy/k8s/deployment.yaml
yq -o json '.features' config/app.yaml
yq '.spec.replicas = 5' deploy/k8s/deployment.yaml | rg replicas

Expected:

db.lab.internal
ghcr.io/example/shop:1.4.2
{
  "rabatt": false,
  "newsletter": true
}
  replicas: 5

Without -i, yq only writes to stdout. The file stays unchanged. With yq -i you modify it in place, so only on a clean Git state.

Save your progress? Sign up for free

Drill 7: delta instead of diff

sed 's/log_level: info/log_level: debug/' config/app.yaml > /tmp/lab-app.yaml
diff -u config/app.yaml /tmp/lab-app.yaml
delta config/app.yaml /tmp/lab-app.yaml

Expected (shortened, without colors):

@@ -1,6 +1,6 @@
 service: shop
 port: 8080
-log_level: info
+log_level: debug
 database:

config/app.yaml ⟶   tmp/lab-app.yaml
────────────────────────────────────────────────────────────
───┐
1: │
───┘
service: shop
port: 8080
log_level: info
log_level: debug

In the terminal the lines have red and green backgrounds, and the changed word is additionally highlighted. For code reviews the side-by-side view is powerful:

git diff main feature/rabatt -- config | delta --side-by-side --width 96

Expected (shortened):

config/app.yaml
─────────────────────────────────────────────────────────────────────
│  8 │features:                    │  8 │features:
│  9 │  rabatt: false              │  9 │  rabatt: true
│ 10 │  newsletter: true           │ 10 │  newsletter: true

You’ll set up delta as the default pager for git diff, git log -p and git show on Day 10 in the Git configuration.

Save your progress? Sign up for free

Drill 8: btop, tldr and httpie in fast-forward

btop instead of top: Start btop. The most important keys:

Key Effect Mnemonic
f filter processes filter
k kill the selected process kill
e tree view on/off tree
1–4 toggle CPU/memory/network/process boxes number of the box
q quit quit

tldr instead of man: examples instead of a manual. The Brewfile installs tlrc, the command is called tldr.

tldr tar

Expected (shortened, may differ depending on version):

  tar

  Archiving utility.

  [c]reate an archive and write it to a [f]ile:

      tar cf path/to/target.tar path/to/file1 path/to/file2 ...

The real man page remains the reference. With MANPAGER from tools.zsh it’s now in color: man rg.

httpie instead of curl: start a test server and compare:

python3 -m http.server 8765 >/dev/null 2>&1 &
curl -s -i localhost:8765/config/app.json | head -2
curl -s localhost:8765/config/app.json | jq .port
http :8765/config/app.json
kill %1

Expected (http part shortened, may differ depending on version):

HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.14.8
8080
HTTP/1.0 200 OK
Content-type: application/json

{
    "features": {
        "newsletter": true,
        "rabatt": false
    },
    "port": 8080,

http formats JSON and colors headers. :8765 is short for localhost:8765. POST with JSON: http POST :8080/api/cart sku=A1 qty:=2 (= string, := number/JSON).

Save your progress? Sign up for free

Shortcut table

Old New Mnemonic
grep -rn x . rg x (-t go, -w, -l, -C1, -uu) ripgrep
find . -name '*.go' fd -e go (-t d, -H, -u, -x, -X) find
cat datei bat datei (-r 10:20, -A, -l yaml) a cat with wings
ls -la ll, la, lt (eza) long, all, tree
cd pfad/zu/ziel z ziel, zi z as in zoxide
grep on JSON/YAML jq '.a.b', yq '.a.b' query
diff -u a b delta a b, git diff with delta river delta
top / man / curl btop / tldr / http tl;dr

Checkpoint

for t in rg fd bat eza zoxide jq yq delta btop; do
  (( $+commands[$t] )) && echo "✔ $t" || echo "✘ $t fehlt"
done
[[ $(alias ll) == *eza* ]] && echo "✔ Alias ll" || echo "✘ Alias ll"
[[ -r $RIPGREP_CONFIG_PATH ]] && echo "✔ ripgreprc" || echo "✘ ripgreprc"
[[ $_ZO_DATA_DIR == $LAB/* ]] && echo "✔ zoxide im Lab" || echo "✘ zoxide-Pfad"
(( $(rg -c TODO | wc -l) == 3 )) && echo "✔ rg ignoriert .git" || echo "✘ rg"
[[ $(yq .port config/app.yaml) == 8080 ]] && echo "✔ yq" || echo "✘ yq"

Expected: all ✔. For tldr and http, brew bundle check tells you if they’re missing.

Challenge

Write a one-liner that checks whether replicas in config/app.json and in deploy/k8s/deployment.yaml match. It prints ✔ replicas gleich (3) (“replicas equal”) or ✘ app.json=… deployment=….

Hint: Read both values into variables and compare with [[ … == … ]].

Solution

a=$(jq .replicas config/app.json); b=$(yq .spec.replicas deploy/k8s/deployment.yaml)
[[ $a == "$b" ]] && echo "✔ replicas gleich ($a)" || echo "✘ app.json=$a deployment=$b"

Expected:

✔ replicas gleich (3)

Cross-check without changing the file: replace b=… with b=$(yq '.spec.replicas = 5 | .spec.replicas' deploy/k8s/deployment.yaml).

Save your progress? Sign up for free

Enterprise Note

  • Scripts, Dockerfiles and CI jobs use POSIX tools (grep, find, sed). rg, fd and eza usually aren’t available there.
  • jq and yq belong in CI images. Watch out: there are two yqs (Mike Farah, Go, and kislyuk, Python) with different syntax. Pin the version.
  • rg respects .gitignore. For audits looking for secrets, use rg -uu or, better, specialized scanners like gitleaks.
  • In company networks, http/curl often need a proxy and custom CA certificates (HTTPS_PROXY, --verify).
  • New tools reach the team via the Brewfile. That way everyone has the same versions (Day 13).