Welcome to bashoneliners.com, a growing collection of practical and well-explained Bash one-liners, snippets, tips and tricks. We review and improve every contributed one-liner to make sure it is of high quality: useful, easy to read, follows best practices, with clear, detailed, accurate explanation. These one-liners should help you automate tasks, troubleshoot problems, whether it be in system administration, file management, networking or programming.
lsof / | awk '$7 > 1048576 { print $7 / 1048576 "MB", $9, $1 }' | sort -nu | tail
find ~ -type d -name .git | sed 's?/\.git$??' | awk '{ print "-------------------------"; print "\033[1;32mGit Repo:\033[0m " $0; system("git --git-dir=\""$0"\"/.git --work-tree=\""$0"\" status")}'
echo {01..10}
while true; do clear; date; echo; echo "[Count] | [IP ADDR]"; echo "-------------------"; netstat -n | grep ':80\>' | awk '! /LISTEN/ {print $5}' | cut -d: -f1 | uniq -c; sleep 5; done
for name in *; do mv "$name" "${name,,}"; done
for path in *.avi; do echo "${path%.avi}"; done | xargs -I{} -P9 HandBrakeCLI -i {}.avi -o {}.mp4
command1 && command2 || command3
ifconfig -a | perl -lne 'print $_ for /\b(?!255)(?:\d{1,3}\.){3}(?!255)\d{1,3}\b/g' | xargs nmap -A -p0-
watch --interval 5 killall -USR1 dd
find . -type f -mtime +1 -name "*.log" -exec zip -m {}.zip {} \; >/dev/null
netstat -tn 2>/dev/null | awk '/:80\>/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head
git commit -m "$(w3m whatthecommit.com | head -n 1)"
$TERMINAL & disown
grep "phpmyadmin" $path_to_access.log | grep -Po "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" | sort | uniq | xargs -I% sudo iptables -A INPUT -s % -j DROP
echo "Example command output..." | tee >(pbcopy)
find . -type f -name '*.java' -exec sh -c 'iconv -f cp1252 -t utf-8 "$1" > converted && mv converted "$1"' -- {} \;
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
printf '%s\n' {1..10}
sudo -s <<< 'apt update -y && apt upgrade -y'
cwd=$(cd "$(dirname "$0")" && pwd)
for ((i=1; i<=10; ++i)); do echo $i; done
fac() { { echo 1; seq $1; } | paste -s -d\* | bc; }
find . -name '*conf*' -exec grep -Hni 'text to match' {} \; > matches.txt
dig +short myip.opendns.com @resolver1.opendns.com
ssh-keygen -R <hostname>