DEV Community

Daniil Kornilov
Daniil Kornilov

Posted on Edited on

Seven terminal patterns for inspecting files, APIs and Git history

Disclosure: This article was created or edited with AI assistance. It is educational guidance, not a report of measured results. No measured productivity, hiring, sales or income outcome is claimed. Examples are illustrative unless a source is explicitly given.

The code blocks are educational examples, not a verified production package. Check dependencies, platform compatibility and behavior in your own project.

The examples below illustrate command-line patterns. Check the working directory and inputs before running a command; available commands differ between systems.

1. git log --oneline --graph --all

This command can help inspect:

  • All branches visually
  • Commit history at a glance
  • Where branches diverge and merge
# Even better, alias it:
alias gl="git log --oneline --graph --all --decorate"
Enter fullscreen mode Exit fullscreen mode

2. curl -s URL | jq .

Test APIs without Postman:

curl -s https://api.github.com/users/octocat | jq '.name, .bio'
Enter fullscreen mode Exit fullscreen mode

jq is a game-changer for working with JSON. Learn it once, use it forever.

3. find . -name "*.log" -mtime +7 -print

List older log files before deciding whether any should be removed:

# Preview older log files
find . -type f -name "*.log" -mtime +7 -print

# Find large files
find . -size +100M -type f

# Find recently modified files
find . -mmin -30 -type f
Enter fullscreen mode Exit fullscreen mode

4. watch -n 5 command

Run any command every N seconds:

# Monitor disk space
watch -n 5 df -h

# Watch pod status
watch -n 2 kubectl get pods

# Monitor log file
watch -n 1 "tail -5 app.log"
Enter fullscreen mode Exit fullscreen mode

5. history | awk '{print $2}' | sort | uniq -c | sort -rn | head -10

This illustrative pipeline summarizes the command-history format of some shells. Inspect your own history output first; field positions and configuration differ.

# Illustrative output:
# 287 git
# 203 cd
# 156 python
Enter fullscreen mode Exit fullscreen mode

If you type something 100+ times, alias it.

6. xargs (The Multiplier)

Run a command on multiple inputs:

# Print each Python cache file as one argument, including names with spaces.
find . -type f -name "*.pyc" -print0 | xargs -0 -n 1 printf '%s\n'
Enter fullscreen mode Exit fullscreen mode

This example only prints paths. Avoid parsing ps output into a blanket kill command, and inspect any deletion or process target explicitly.

7. && and || (Flow Control)

# Run next command only if previous succeeds
npm test && npm run build

# Run fallback if command fails
git pull || echo "Pull failed, check your connection"

# Combined
make build && echo "Success!" || echo "Build failed"
Enter fullscreen mode Exit fullscreen mode

Simple but powerful. Chain operations with confidence.

Bonus: Create a .aliases File

# ~/.aliases
alias gs="git status"
alias gp="git push"
alias dc="docker compose"
alias py="python3"
alias serve="python3 -m http.server 8000"
alias ports="lsof -i -P -n | grep LISTEN"
Enter fullscreen mode Exit fullscreen mode

Use a terminal or a GUI according to the task. The useful skill is understanding the command and its effects, not demonstrating seniority.

Top comments (0)