Bash One-Liners for Daily Work¶
A one-liner in Bash is a single-line command that solves a specific problem. This collection contains dozens of proven one-liners.
Finding Files¶
find / -type f -size +100M -exec ls -lh {} \; find /var/log -type f -mtime -1 grep -rn ‘error’ /var/log/ –include=’*.log’
Text Processing¶
awk ‘{print $1}’ access.log | sort | uniq -c | sort -rn | head -10 find . -name ‘*.conf’ -exec sed -i ‘s/old/new/g’ {} + grep -oP ‘[\w.+-]+@[\w-]+.[\w.]+’ file.txt | sort -u
System Info¶
ps aux –sort=-%mem | head -11 du -sh /* 2>/dev/null | sort -rh | head -10 ss -tlnp
Docker¶
docker container prune -f docker system df docker ps -q | xargs -I {} docker exec {} uptime
JSON and CSV¶
curl -s api.example.com/data | python3 -m json.tool column -t -s’,’ data.csv | head -20 awk -F’,’ ‘{sum+=$3} END {print sum}’ data.csv
One-Liner = Productivity¶
Save your favorites to ~/.bash_aliases. Gradually build up your command arsenal.