| name | one-liners |
| description | Command-line one-liners for file manipulation, text processing, system administration, and quick automation. Use when user mentions "one-liner", "quick command", "bash one-liner", "command line trick", "shell trick", "pipe chain", "quick script", "inline command", "find and replace all files", "bulk rename", "process log files", "count lines", "disk usage", or needs a single-line shell command to solve a problem fast. |
One-Liners
Quick reference for single-line shell commands. For helper functions see scripts/bash-helpers.sh and scripts/system-diagnostics.sh. For extended examples see references/bash-oneliners.md and references/advanced-oneliners.md. Structured examples in examples/common-oneliners.json.
File Operations
find . -name "*.log" -type f
find . -type f -size +100M -exec ls -lh {} +
find . -type f -mtime -1
find . -type f \( -name "*.ts" -o -name "*.tsx" \)
for f in *.jpeg; do mv "$f" "${f%.jpeg}.jpg"; done
for f in *; do mv "$f" "$(echo "$f" | tr 'A-Z' 'a-z')"; done
n=1; for f in *.png; do mv "$f" "$(printf '%03d.png' $n)"; ((n++)); done
rename 's/IMG_(\d+)/photo_$1/' *.jpg
find /tmp -type f -mtime +30 -delete
find . -name "node_modules" -type d -prune -exec rm -rf {} +
find . -type d -empty -delete
ls -tp | grep -v '/$' | tail -n +6 | xargs rm --
find . -type f -exec md5sum {} + | sort | uniq -w32 -dD
find . -type d -exec chmod 755 {} + && find . -type f -exec chmod 644 {} +
find . -name "*.sh" -exec chmod +x {} +
find / -type f -perm -o+w 2>/dev/null
find / -nouser 2>/dev/null
tar -czf backup-$(date +%Y%m%d-%H%M%S).tar.gz directory/
Text Processing
grep Pipelines
grep -rn "TODO" --include="*.py" -A 2
grep -rc "import" --include="*.ts" . | grep -v ":0$" | sort -t: -k2 -rn
grep -v "^#" config.txt | grep -v "^$"
grep -E "error|warn|fatal" app.log
grep -oP '(?<=email=)[^\s&]+' access.log
grep -rL "use strict" --include="*.js" .
awk Columns
awk '{print $1, $4}' access.log
awk '{sum += $3} END {print sum}' data.txt
awk -F, '$3 > 100 {print $1, $3}' data.csv
awk '{count[$1]++} END {for (k in count) print k, count[k]}' access.log | sort -k2 -rn
awk '!seen[$0]++' file.txt
awk '{sum+=$1; sumsq+=$1*$1; n++} END {print "avg=" sum/n, "std=" sqrt(sumsq/n-(sum/n)^2)}' numbers.txt
sed Replacements
find . -name "*.js" -exec sed -i '' 's/oldFunc/newFunc/g' {} +
find . -name "*.js" -exec sed -i 's/oldFunc/newFunc/g' {} +
sed '/^#/d' config.txt
sed -n '/BEGIN/,/END/p' file.txt
sed '10,20s/foo/bar/g' file.txt
sed 's/\x1b\[[0-9;]*m//g' colored-output.txt
sed '/\[dependencies\]/a new_dep = "1.0"' Cargo.toml
Sorting and Counting
sort | uniq -c | sort -rn
sort file.txt | uniq -c | sort -rn | head -10
sort -t, -k3 -n data.csv
find . -type f | sed 's/.*\.//' | sort | uniq -c | sort -rn
find . -name "*.py" -exec grep -cv '^[[:space:]]*$\|^[[:space:]]*#' {} + | awk -F: '{sum+=$2} END {print sum}'
System Information
du -sh */ | sort -rh | head -10
df -h
df -i
ps aux --sort=-%mem | head -10
ps aux -m | head -10
ps aux --sort=-%cpu | head -10
ps aux -r | head -10
free -h
nproc
sysctl -n hw.ncpu
ss -tlnp
lsof -iTCP -sTCP:LISTEN -n -P
lsof -p $(pgrep -f myapp)
fuser /var/log/syslog
lsof /var/log/system.log
watch -n 1 'uptime; free -h; df -h /'
Process Management
lsof -i :8080
lsof -ti :8080 | xargs kill -9
pkill -f "node server.js"
watch -n 1 "ps aux | grep '[n]ode'"
nohup ./long-task.sh > output.log 2>&1 &
timeout 30s ./slow-script.sh
gtimeout 30s ./slow-script.sh
ps aux | awk '$8 == "Z" {print}'
kill $(pgrep -f myapp) && sleep 5 && kill -9 $(pgrep -f myapp) 2>/dev/null
Git One-Liners
git shortlog -sn --all
git log --format='%ai' | cut -d' ' -f1 | sort | uniq -c
git log --pretty=format: --name-only | sort | uniq -c | sort -rn | head -20
git log --author="name" --pretty=tformat: --numstat | awk '{a+=$1; r+=$2} END {print "+" a, "-" r}'
git blame -L 10,20 file.js
git log -p -S "deletedFunction" --all
git log --all --grep="fix login"
git log --diff-filter=D --summary | grep "delete.*filename"
git branch --merged main | grep -v "main" | xargs git branch -d
git remote prune origin
git clean -nd && git clean -fd
git gc --aggressive --prune=now
git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | awk '/^blob/ {print $3, $4}' | sort -rn | head -20
Network
curl -o /dev/null -s -w "%{time_total}\n" https://example.com
curl -LIs https://example.com
curl -s -X POST -H "Content-Type: application/json" -d '{"key":"val"}' https://api.example.com
curl --retry 3 --retry-delay 2 --retry-max-time 30 https://api.example.com/data
for url in https://api.example.com/{health,ready,info}; do echo "$url: $(curl -s -o /dev/null -w '%{http_code}' "$url")"; done
dig +short example.com A
dig +short example.com MX
dig -x 93.184.216.34
xargs -n1 curl -O < urls.txt
cat urls.txt | xargs -P 4 -I {} curl -sO {}
echo | openssl s_client -servername example.com -connect example.com:443 2>/dev/null | openssl x509 -noout -dates
for port in 22 80 443 8080; do (echo >/dev/tcp/host/$port) 2>/dev/null && echo "$port open"; done
JSON/YAML Processing
jq
jq . data.json
jq '.results[].name' data.json
jq '[.[] | select(.status == "active")]' users.json
jq -r '.[] | [.id, .name, .email] | @csv' data.json > out.csv
jq -s '.[0] * .[1]' defaults.json overrides.json
jq '[group_by(.status)[] | {status: .[0].status, count: length}]' data.json
jq '.version = "2.0.0"' package.json | sponge package.json
yq
yq '.services.web.image' docker-compose.yml
yq -i '.spec.replicas = 3' deployment.yaml
yq -o=json '.' config.yaml
yq -P '.' config.json
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' base.yaml override.yaml
yq -i 'del(.metadata.annotations)' resource.yaml
Docker One-Liners
docker ps -q | xargs docker stop
docker system prune -af --volumes
docker system df -v
docker stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}"
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name
docker exec -it $(docker ps -lq) sh
docker ps -qf "label=app=myapp" | xargs -I {} docker cp {}:/app/logs ./logs-{}
docker compose logs -f --tail 50 api worker
docker images --format "{{.Size}}\t{{.Repository}}:{{.Tag}}" | sort -rh
docker export container_name | tar -tf - | head -50
macOS-Specific
open .
open -a "Visual Studio Code" file.js
pbcopy < file.txt
pbpaste > output.txt
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
defaults write com.apple.finder AppleShowAllFiles YES; killall Finder
mdfind "kMDItemKind == 'PDF' && kMDItemFSName == '*invoice*'"
say "build complete"
xattr -d com.apple.quarantine /Applications/MyApp.app
system_profiler SPHardwareDataType SPSoftwareDataType
Linux-Specific
inotifywait -m -r -e modify,create,delete ./src
systemctl status nginx && journalctl -u nginx --since "1 hour ago"
apt list --installed 2>/dev/null | grep -i pattern
rpm -qa | grep -i pattern
(crontab -l; echo "0 2 * * * /path/to/backup.sh") | crontab -
for f in /proc/*/status; do awk '/VmSwap|Name/{printf $2 " " $3}' "$f" 2>/dev/null; echo; done | sort -k2 -rn | head -10
ldd /usr/bin/git
Composability Patterns
xargs and parallel
find . -name "*.png" | xargs -P 4 -I {} convert {} -resize 50% {}
find . -name "*.log" -print0 | xargs -0 rm
git branch --merged | grep -v main | xargs -I {} git branch -d {}
parallel convert {} -resize 800x {} ::: *.jpg
parallel -a hosts.txt ping -c 1 {}
find . -name "*.csv" | parallel -j$(nproc) "wc -l {}"
parallel --bar gzip ::: *.log
tee and Process Substitution
make 2>&1 | tee build.log
diff <(ls dir1) <(ls dir2)
tail -f app.log | tee >(grep ERROR >> errors.log) >(grep WARN >> warnings.log)
curl -s https://api.example.com/data | tee response.json | jq '.count'
Pipeline Recipes
grep -rn "TODO\|FIXME" --include="*.py" | sort -t: -k1,1 -k2,2n
find . -type f -mtime -7 -exec du -h {} + | sort -rh | head -10
watch -d -n 5 'curl -s https://api.example.com/status | jq .health'
curl -s https://api.example.com/users | jq -r '.[] | [.id, .email] | @csv' >> users.csv
until curl -sf http://localhost:8080/health; do sleep 2; done; echo "Service up"
python3 -m http.server 8000
echo -n "secret" | base64
echo "c2VjcmV0" | base64 -d
Reference Files
scripts/bash-helpers.sh -- Reusable shell functions for port checking, JSON conversion, container ops, git cleanup
scripts/system-diagnostics.sh -- Functions for CPU, memory, network, and disk diagnostics
references/bash-oneliners.md -- Categorized one-liners for files, git, network, docker, performance
references/advanced-oneliners.md -- Advanced data processing, system admin, development workflows
examples/common-oneliners.json -- Structured one-liner examples with categories and descriptions