Skip to content

Portal | Level: L0: Entry | Topics: Modern CLI Tools, jq / JSON Processing, ripgrep (rg), fzf | Domain: CLI Tools

Modern CLI Tools Drills

Remember: Modern CLI tool replacements: find -> fd, grep -> rg (ripgrep), cat -> bat, ls -> eza, du -> dust/ncdu, cd -> zoxide, curl -> httpie. All are faster, have saner defaults, and respect .gitignore by default. You do not need to memorize every flag — the defaults are already what you want 90% of the time.

One-liner: rg is faster than grep because it uses memory-mapped I/O, parallelizes across cores, and skips .git/ and .gitignore'd files by default. On a large repo, rg can be 5-10x faster than grep -r. Use --no-ignore when you need to search ignored files.

Drill 1: Find Files by Extension with fd

Difficulty: Easy

Q: Find all .yaml files in the current directory tree using fd.

Answer
fd -e yaml

# With classic find equivalent:
find . -name "*.yaml" -type f

# fd advantages:
# - Respects .gitignore by default
# - Colorized output
# - Simpler syntax
# - Much faster on large repos

Drill 2: Search Code with ripgrep

Difficulty: Easy

Q: Search all Go files for the string context.TODO() using rg.

Answer
rg 'context\.TODO\(\)' -t go

# Useful flags:
rg 'pattern' -t go          # Filter by file type
rg 'pattern' -g '*.go'      # Glob filter
rg 'pattern' -l             # Only show filenames
rg 'pattern' -c             # Count matches per file
rg 'pattern' -C 3           # 3 lines of context
rg 'pattern' --no-ignore    # Don't respect .gitignore

Drill 3: Preview Files with bat

Difficulty: Easy

Q: View a YAML file with syntax highlighting and line numbers using bat.

Answer
bat deployment.yaml

# Useful options:
bat -l yaml file.txt         # Force language detection
bat -r 10:20 file.yaml       # Show only lines 10-20
bat -A file.yaml             # Show non-printable characters
bat --diff file.yaml         # Show git diff alongside

# Use as a pager for other commands:
kubectl get pods -o yaml | bat -l yaml

Drill 4: Process JSON with jq

Difficulty: Medium

Q: Extract all pod names from kubectl get pods -o json using jq.

Answer
kubectl get pods -o json | jq -r '.items[].metadata.name'

# Common jq patterns:
jq '.items[] | {name: .metadata.name, status: .status.phase}'
jq '.items[] | select(.status.phase == "Running")'
jq '.items | length'                    # Count items
jq -r '.items[].metadata.name'         # Raw output (no quotes)
jq -S '.'                              # Sort keys (diff-friendly)

Drill 5: Navigate Directories with zoxide

Difficulty: Easy

Q: How do you jump to a previously visited directory matching "terraform" using zoxide?

Answer
z terraform

# zoxide learns from your cd usage:
z terra              # Fuzzy match
z proj terra         # Multiple keywords (project with terraform)
zi                   # Interactive selection with fzf

# Setup (add to .bashrc/.zshrc):
eval "$(zoxide init bash)"   # or zsh/fish

Drill 6: Interactive Filtering with fzf

Difficulty: Medium

Q: Use fzf to interactively select a Kubernetes context and switch to it.

Answer
kubectl config get-contexts -o name | fzf | xargs kubectl config use-context

# More fzf patterns:
# Interactive file open:
vim $(fzf)

# Preview files while selecting:
fzf --preview 'bat --color=always {}'

# Git branch checkout:
git branch | fzf | xargs git checkout

# Kill a process interactively:
ps aux | fzf | awk '{print $2}' | xargs kill

# Search and open:
rg --files | fzf --preview 'bat --color=always {}' | xargs vim

Drill 7: Disk Usage with dust/ncdu

Difficulty: Easy

Q: Find which directories are consuming the most disk space in /var/log using dust.

Answer
dust /var/log

# dust shows a visual bar chart of disk usage
# Sorted by size, with depth control:
dust -n 10 /var/log          # Top 10 entries
dust -d 2 /var/log           # Max depth 2

# ncdu alternative (interactive):
ncdu /var/log
# Navigate with arrows, press 'd' to delete, 'q' to quit

# Classic equivalent:
du -sh /var/log/* | sort -rh | head -10

Drill 8: Better ls with exa/eza

Difficulty: Easy

Q: List files with git status indicators and tree view using eza (formerly exa).

Answer
eza --long --git --tree --level=2

# Useful combinations:
eza -la --git              # Long list with git status
eza --tree --level=3       # Tree view, 3 levels deep
eza -la --sort=modified    # Sort by modification time
eza --icons                # Show file type icons
eza -la --header           # Show column headers

# Classic equivalent:
ls -la                     # No git info, no tree

Drill 9: HTTP Testing with httpie

Difficulty: Medium

Q: Send a POST request with JSON body to a local API using httpie (http command).

Answer
http POST localhost:8080/api/users name=alice role=admin

# httpie auto-detects content type:
http POST :8080/api/users name=alice role=admin    # JSON by default
http -f POST :8080/login user=alice pass=secret    # Form data
http GET :8080/api/users Authorization:"Bearer tok" # Headers

# Compare with curl:
curl -X POST http://localhost:8080/api/users \
  -H 'Content-Type: application/json' \
  -d '{"name": "alice", "role": "admin"}'

# httpie advantages:
# - JSON by default
# - Colorized output
# - Simpler header/body syntax

Drill 10: Combining Tools in Pipelines

Difficulty: Hard

Q: Find all Kubernetes manifests that define a Deployment with more than 3 replicas. Use modern CLI tools.

Answer
# Using fd + rg + jq:
fd -e yaml | xargs rg -l 'kind: Deployment' | \
  xargs -I{} sh -c 'yq ".spec.replicas" {} 2>/dev/null' | \
  awk '$1 > 3'

# More practical approach with yq:
fd -e yaml -x sh -c '
  if yq -e ".kind == \"Deployment\" and .spec.replicas > 3" {} >/dev/null 2>&1; then
    echo "{}: $(yq .spec.replicas {})"
  fi
'

# Or with rg for a quick scan:
rg -l 'kind: Deployment' -g '*.yaml' | while read f; do
  replicas=$(yq '.spec.replicas // 0' "$f" 2>/dev/null)
  [ "$replicas" -gt 3 ] 2>/dev/null && echo "$f: $replicas replicas"
done
Key insight: chain `fd` (find) → `rg` (filter) → `yq`/`jq` (parse) for YAML/JSON workflows.

Drill 11: tmux Session Management

Difficulty: Medium

Q: Create a named tmux session with 3 windows (editor, logs, shell) in one command sequence.

Answer
tmux new-session -d -s work -n editor \; \
  new-window -t work -n logs \; \
  new-window -t work -n shell \; \
  attach -t work

# Essential tmux commands (prefix = Ctrl-b):
# Ctrl-b c     Create new window
# Ctrl-b n/p   Next/previous window
# Ctrl-b %     Split vertical
# Ctrl-b "     Split horizontal
# Ctrl-b d     Detach
# Ctrl-b [     Scroll mode (q to exit)

# Session management:
tmux ls                     # List sessions
tmux attach -t work         # Reattach
tmux kill-session -t work   # Clean up

Drill 12: yq for YAML Processing

Difficulty: Medium

Q: Use yq to change the image tag in a Kubernetes deployment YAML from v1.0 to v2.0 in-place.

Answer
yq -i '.spec.template.spec.containers[0].image = "myapp:v2.0"' deployment.yaml

# Common yq operations:
yq '.metadata.name' file.yaml              # Read a field
yq '.spec.replicas = 5' file.yaml          # Set a field (stdout)
yq -i '.spec.replicas = 5' file.yaml       # Set in-place
yq '. * load("patch.yaml")' base.yaml      # Merge files
yq ea 'select(di == 0)' multi.yaml         # First document only
yq -o json file.yaml                       # Convert to JSON
yq -P file.json                            # Convert JSON to YAML

# Combine with fd for bulk operations:
fd -e yaml -x yq -i '.metadata.labels.version = "v2"' {}

Wiki Navigation

Prerequisites

  • Modern CLI Tools (Topic Pack, L0) — fzf, jq / JSON Processing, Modern CLI Tools
  • Skillcheck: Modern CLI Tools (Assessment, L0) — fzf, jq / JSON Processing, Modern CLI Tools
  • CLI Tools Flashcards (CLI) (flashcard_deck, L1) — Modern CLI Tools
  • Modern CLI Flashcards (CLI) (flashcard_deck, L1) — Modern CLI Tools
  • Ripgrep Flashcards (CLI) (flashcard_deck, L1) — ripgrep (rg)
  • YAML, JSON & Config Formats (Topic Pack, L1) — jq / JSON Processing
  • fzf (Topic Pack, L1) — fzf
  • fzf Flashcards (CLI) (flashcard_deck, L1) — fzf
  • jq (Topic Pack, L1) — jq / JSON Processing
  • jq Flashcards (CLI) (flashcard_deck, L1) — jq / JSON Processing