Welcome to bashoneliners.com, a growing collection of practical and well-explained Bash tips and tricks. We are committed to review every contributed one-liner to ensure its high quality, practical usefulness, and a solid explanation of how it works. We want to document one-liners for frequent (non-trivial) tasks executed in the shell, written in the best possible way, following good practices known in the industry. To get the latest Bash one-liners, follow @bashoneliners on Twitter. If you find any problems, please report on GitHub Issues.
1 score

Delete static and dynamic arp for /24 subnet

 $ for i in {1..254}; do arp -d 192.168.0.$i; done

Oct. 21, 2016, 5:07 a.m.dennyhalim.com

8 score

List status of all GIT repos

 $ find ~ -name ".git" 2> /dev/null | sed 's/\/.git/\//g' | awk '{print "-------------------------\n\033[1;32mGit Repo:\033[0m " $1; system("git --git-dir="$1".git --work-tree="$1" status")}'

Oct. 16, 2016, 11:19 p.m.uMt

1 score

Shuffle lines

 $ ... | perl -MList::Util=shuffle -e 'print shuffle <>;'

Jan. 31, 2016, 9:02 p.m.openiduser81

0 score

Create an array of CPU frequencies in GHz

 $ cpus=($({ echo scale=2; awk '/cpu MHz/ {print $4 " / 1000"}' /proc/cpuinfo; } | bc))

Dec. 28, 2015, 9:02 p.m.openiduser146

0 score

Test git archive before actually creating an archive // fake dry run

 $ git archive master some/project/subdir | tar t

Dec. 22, 2015, 2:29 p.m.openiduser146

1 score

Convert all flac files in dir to mp3 320kbps using ffmpeg

 $ for FILE in *.flac; do ffmpeg -i "$FILE" -b:a 320k "${FILE[@]/%flac/mp3}"; done;

Sept. 20, 2015, 5:45 p.m.Orkan

1 score

Preserve your fingers from cd ..; cd ..; cd..; cd..;

 $ upup(){ DEEP=$1; [ -z "${DEEP}" ] && { DEEP=1; }; for i in $(seq 1 ${DEEP}); do cd ../; done; }

June 9, 2015, 3:09 p.m.andreaganduglia

1 score

Get number of all Python Behave scenarios (including all examples from Scenario Outlines)

 $ behave -d | grep "scenarios passed" | cut -d, -f4 | sed -e 's/^[[:space:]]*//' | sed 's/untested/scenarios/g'

April 17, 2015, 2:21 p.m.openiduser188

4 score

Ban all IPs that attempted to access phpmyadmin on your site

 $ 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

April 2, 2015, 8:58 a.m.openiduser187

-1 score

Get a free shell account on a community server

 $ sh <(curl hashbang.sh | gpg)

March 15, 2015, 9:49 a.m.lrvick

0 score

Shuffle lines

 $ seq 5 | shuf

March 12, 2015, 7:58 a.m.openiduser184

6 score

Generate a sequence of numbers

 $ echo {01..10}

March 1, 2015, 12:04 a.m.Elkku

3 score

Run a command and copy its output to clipboard (Mac OSX)

 $ echo "Here comes the output of my failing code" | tee >(pbcopy)

Feb. 28, 2015, 11:53 p.m.Elkku

4 score

Nmap scan every interface that is assigned an IP

 $ ifconfig -a | grep -Po '\b(?!255)(?:\d{1,3}\.){3}(?!255)\d{1,3}\b' | xargs nmap -A -p0-

Feb. 8, 2015, 2:11 a.m.ratchode

0 score

Download a file from a webserver with telnet

 $ (echo 'GET /'; echo; sleep 1; ) | telnet www.google.com 80

Dec. 22, 2014, 11:31 p.m.Janos

0 score

Print the window title of current mpv session to display what is playing

 $ wmctrl -pl | grep $(pidof mpv) | cut -d- -f2-

Dec. 15, 2014, 3:37 a.m.openiduser171

4 score

Change the encoding of all files in a directory and subdirectories

 $ find . -type f  -name '*.java' -exec sh -c 'iconv -f cp1252 -t utf-8 "$1" > converted && mv converted "$1"' -- {} \;

Nov. 20, 2014, 12:15 p.m.Janos

2 score

Generate a sequence of numbers

 $ for ((i=1; i<=10; ++i)); do echo $i; done

Nov. 4, 2014, 12:29 p.m.Janos

0 score

Shuffle lines

 $ ... | perl -MList::Util -e 'print List::Util::shuffle <>'

Oct. 25, 2014, 10:40 p.m.Janos

1 score

Print a flat list of dependencies of a Maven project

 $ mvn dependency:list | sed -ne s/..........// -e /patterntoexclude/d -e s/:compile//p -e s/:runtime//p | sort | uniq

Sept. 22, 2014, 9:02 p.m.Janos

1 score

Open Windows internet shortcut (*.url) files in firefox

 $ grep -i url='*' file.url | cut -b 5- | xargs firefox

Sept. 12, 2014, 12:06 a.m.tsjswimmer

0 score

Open Windows internet shortcut (*.url) files in firefox

 $ firefox $(grep -i ^url='*' file.url | cut -b 5-)

Sept. 11, 2014, 10:03 a.m.tsjswimmer

1 score

Remove all at jobs

 $ atq | sed 's_\([0-9]\{1,8\}\).*_\1_g' | xargs atrm

Sept. 10, 2014, 9:56 a.m.laurip

5 score

Corporate random bullshit generator (cbsg)

 $ curl -s http://cbsg.sourceforge.net/cgi-bin/live | grep -Eo '^<li>.*</li>' | sed s,\</\\?li\>,,g | shuf -n 1

Sept. 4, 2014, 3:44 p.m.Genunix

1 score

Deletes orphan vim undo files

 $ find . -type f -iname '*.un~' | while read UNDOFILE ; do FILE=$( echo "$UNDOFILE" | sed -r -e 's/.un~$//' -e 's&/\.([^/]*)&/\1&' ) ; [[ -e "$FILE" ]] || rm "$UNDOFILE" ; done

Sept. 2, 2014, 6:51 p.m.rafaeln