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.
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 by name, size, or age
find . -name "*.log" -type f
find . -type f -size +100M -execls -lh {} +
find . -type f -mtime -1 # Modified in last 24h
find . -type f \( -name "*.ts" -o -name "*.tsx" \)
# Bulk renamefor f in *.jpeg; domv"$f""${f%.jpeg}.jpg"; done
f *; ;
n=1; f *.png; ; ((n++));
rename *.jpg
find /tmp - f -mtime +30 -delete
find . -name - d -prune - -rf {} +
find . - d -empty -delete
-tp | grep -v | -n +6 | xargs --
find . - f - {} + | | -w32 -dD
find . - d - 755 {} + && find . - f - 644 {} +
find . -name - +x {} +
find / - f -perm -o+w 2>/dev/null
find / -nouser 2>/dev/null
tar -czf backup-$( +%Y%m%d-%H%M%S).tar.gz directory/
awk '{print $1, $4}' access.log # Specific columns
awk '{sum += $3} END {print sum}' data.txt # Sum column
awk -F, '$3 > 100 {print $1, $3}' data.csv # Filter by value
awk '{count[$1]++} END {for (k in count) print k, count[k]}' access.log | sort -k2 -rn
awk '!seen[$0]++' file.txt # Deduplicate preserving order
awk '{sum+=$1; sumsq+=$1*$1; n++} END {print "avg=" sum/n, "std=" sqrt(sumsq/n-(sum/n)^2)}' numbers.txt
sed Replacements
# In-place replacement across files
find . -name "*.js" -exec sed -i '''s/oldFunc/newFunc/g' {} + # macOS
find . -name "*.js" -exec sed -i 's/oldFunc/newFunc/g' {} + # Linux
sed '/^#/d' config.txt # Delete comment lines
sed -n '/BEGIN/,/END/p' file.txt # Extract between markers
sed '10,20s/foo/bar/g' file.txt # Replace on specific lines
sed 's/\x1b\[[0-9;]*m//g' colored-output.txt # Strip ANSI codes
sed '/\[dependencies\]/a new_dep = "1.0"' Cargo.toml # Insert line after match
Sorting and Counting
sort | uniq -c | sort -rn # Frequency countsort file.txt | uniq -c | sort -rn | head -10 # Top 10 most commonsort -t, -k3 -n data.csv # Sort CSV by column 3
find . -type f | sed 's/.*\.//' | sort | uniq -c | sort -rn # LOC per extension
find . -name "*.py" -exec grep -cv '^[[:space:]]*$\|^[[:space:]]*#' {} + | awk -F: '{sum+=$2} END {print sum}'
System Information
# Diskdu -sh */ | sort -rh | head -10 # Largest directoriesdf -h # Disk usage summarydf -i # Inode usage# Memory and CPU
ps aux --sort=-%mem | head -10 # Linux: top by memory
ps aux -m | head -10 # macOS: top by memory
ps aux --sort=-%cpu | head -10 # Linux: top by CPU
ps aux -r | head -10 # macOS: top by CPU
free -h # Linux memory summarynproc# Linux CPU count
sysctl -n hw.ncpu # macOS CPU count# Network connections
ss -tlnp # Linux: listening ports
lsof -iTCP -sTCP:LISTEN -n -P # macOS: listening ports
lsof -p $(pgrep -f myapp) # Open files by process
fuser /var/log/syslog # Linux: who uses a file
lsof /var/log/system.log # macOS: who uses a file
watch -n 1 'uptime; free -h; df -h /'# Linux: live dashboard
Process Management
lsof -i :8080 # Find process by port
lsof -ti :8080 | xargs kill -9 # Kill process on port
pkill -f "node server.js"# Kill by pattern
watch -n 1 "ps aux | grep '[n]ode'"# Monitor processnohup ./long-task.sh > output.log 2>&1 & # Background with nohuptimeout 30s ./slow-script.sh # Linux: run with timeout
gtimeout 30s ./slow-script.sh # macOS: needs coreutils
ps aux | awk '$8 == "Z" {print}'# List zombie processeskill $(pgrep -f myapp) && sleep 5 && kill -9 $(pgrep -f myapp) 2>/dev/null # Graceful then force
open . # Open Finder here
open -a "Visual Studio Code" file.js # Open with app
pbcopy < file.txt # Copy to clipboard
pbpaste > output.txt # Paste from clipboardsudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder # Flush DNS
defaults write com.apple.finder AppleShowAllFiles YES; killall Finder
mdfind "kMDItemKind == 'PDF' && kMDItemFSName == '*invoice*'"# Spotlight
say "build complete"# Text to speech
xattr -d com.apple.quarantine /Applications/MyApp.app
system_profiler SPHardwareDataType SPSoftwareDataType