Welcome to bashoneliners.com, a curated collection of practical and well-explained Bash one-liners, snippets, tips and tricks. We aim to make each published one-liner to be 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.
grep -xFf file1 file2
sudo cat /proc/1/smaps | grep '^Pss:' | tr -s ' ' | cut -d' ' -f2 | paste -sd+
find . -print0 | xargs -0 -P 40 -n 1 sh -c 'ffmpeg -i "$1" 2>&1 | grep "Duration:" | cut -d " " -f 4 | sed "s/.$//" | tr "." ":"' - | awk -F ':' '{ sum1+=$1; sum2+=$2; sum3+=$3; sum4+=$4; if (sum4 > 100) { sum3+=1; sum4=0 }; if (sum3 > 60) { sum2+=1; sum3=0 }; if (sum2 > 60) { sum1+=1; sum2=0 } if (NR % 100 == 0) { printf "%.0f:%.0f:%.0f.%.0f\n", sum1, sum2, sum3, sum4 } } END { printf "%.0f:%.0f:%.0f.%.0f\n", sum1, sum2, sum3, sum4 }'
git grep -Ew '[A-Z0-9]{20}'
grep -ril '$SEARCH_PATTERN' src | sed -i 's/$FIND_PATTERN/$REPLACE_PATTERN/g'
for ITEM in $(cat values_to_search.txt); do (egrep $ITEM full_values_list.txt && echo $ITEM found) | grep "found" >> exit_FOUND.txt; done
jar tf "$1" | grep '/.*\.class$' | xargs dirname | sort -u | tr / .
comm -23 <(seq "$FROM" "$TO") <(ss -tan | awk '{print $4}' | cut -d':' -f2 | grep "[0-9]\{1,5\}" | sort | uniq) | shuf | head -n "$HOWMANY"
sudo journalctl -b | grep -o "PROTO=.*" | sed -r 's/(PROTO|SPT|DPT|LEN)=//g' | awk '{print $1, $3}' | sort | uniq -c
behave -d | grep "scenarios passed" | cut -d, -f4 | sed -e 's/^[[:space:]]*//' | sed 's/untested/scenarios/g'
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
wmctrl -pl | grep $(pidof mpv) | cut -d- -f2-
grep -i url='*' file.url | cut -b 5- | xargs firefox
firefox $(grep -i ^url='*' file.url | cut -b 5-)
find . -name '*.log' -mtime -2 -exec grep -Hc Exception {} \; | grep -v :0$
sudo dpkg -l | grep libghc | grep "\-dev" | cut -d " " -f 3 | tr '\n' ' ' | sed -e 's/\-dev/\-prof/g' | xargs sudo apt-get install --yes
sudo yum upgrade && for pkg in $(package-cleanup --orphans -q); do repoquery $(rpm -q $pkg --queryformat="%{NAME}") | grep -q ".*" && echo $pkg; done | xargs sudo yum -y remove && for pkg in $(package-cleanup --leaves --all -q); do repoquery --groupmember $pkg | grep -q "@" || echo $pkg; done
find . -name '*conf*' -exec grep -Hni 'text to match' {} \; > matches.txt
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
__=`sensors | grep Core` && echo \(`echo $__ | sed 's/.*+\(.*\).C\(\s\)\+(.*/\1/g' | tr "\n" "+" | head -c-1`\)\/`echo $__ | wc -l` | bc && unset __
for i in *.log; do grep OutOfMemo $i >/dev/null && echo $i oom || echo $i ok; done
echo $(printf %08X 256 | grep -o .. | tac | tr -d '\n')
export psid=$(pgrep -f libflashplayer.so); cp /proc/$psid/fd/$(lsof -p $psid | grep eleted | awk {' print $4 '} | sed -e "s/[a-z]//g") saved.flv
ls | grep '....-..-..-......' | xargs -I {} bash -c "[[ x{} < x$(date -d '3 days ago' +%Y-%m-%d-%H%M%S) ]] && rm -rfv {}"
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'