snippetbashModeratepending
Shell one-liners for common dev tasks
Viewed 0 times
one-linerfindgrepawkshell tricksunix tools
Problem
Need quick shell commands for common development tasks: finding files, processing text, monitoring processes.
Solution
Handy shell one-liners:
# Find files modified in last 24 hours
find . -type f -mtime -1 -not -path './.git/*'
# Find large files (>10MB)
find . -type f -size +10M -not -path './.git/*' | head -20
# Count lines of code by file type
find . -name '*.py' -not -path './.venv/*' | xargs wc -l | tail -1
# Find TODO/FIXME/HACK comments
grep -rn 'TODO\|FIXME\|HACK\|XXX' --include='*.py' .
# Replace string in all files
grep -rl 'oldString' --include='*.ts' . | xargs sed -i '' 's/oldString/newString/g'
# Watch file for changes and re-run command
fswatch -o src/ | xargs -n1 -I{} make test # macOS with fswatch
# Or: while inotifywait -r -e modify src/; do make test; done # Linux
# Show disk usage by directory, sorted
du -sh */ | sort -hr | head -20
# Kill process on a port
lsof -ti:3000 | xargs kill -9 # macOS/Linux
# Quick HTTP server
python3 -m http.server 8080 # Serve current directory
# Pretty-print JSON
cat data.json | python3 -m json.tool
# Or: cat data.json | jq '.'
# Extract unique IPs from log
grep -oE '\b[0-9]{1,3}(\.[0-9]{1,3}){3}\b' access.log | sort -u
# Monitor log file in real-time with filtering
tail -f app.log | grep --line-buffered 'ERROR\|WARN'
# Diff two commands' output
diff <(sort file1.txt) <(sort file2.txt)
# Run command every N seconds
watch -n 5 'kubectl get pods'
# Create timestamped backup
cp config.yml config.yml.$(date +%Y%m%d_%H%M%S).bak
# Parallel command execution (GNU parallel)
cat urls.txt | parallel -j 10 curl -s -o /dev/null -w '%{url} %{http_code}\n'Why
Shell one-liners compose simple Unix tools into powerful operations. Learning the common patterns saves hours of manual work.
Context
Day-to-day development on Unix/Linux/macOS
Revisions (0)
No revisions yet.