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

Go up to a particular folder

 $ alias ph='cd ${PWD%/public_html*}/public_html'

July 18, 2017, 6:07 p.m.Jab2870

3 score

Open another terminal at current location

 $ $TERMINAL & disown

July 18, 2017, 3:04 p.m.Jab2870

1 score

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

 $ up(){ DEEP=$1; for i in $(seq 1 ${DEEP:-"1"}); do cd ../; done; }

June 28, 2017, 5:40 p.m.alireza6677

0 score

Get the HTTP status code of a URL

 $ curl -Lw '%{http_code}' -s -o /dev/null -I SOME_URL

June 19, 2017, 11:15 p.m.Janos

0 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 | cowsay

June 7, 2017, 4:11 p.m.Jab2870

1 score

Generate a sequence of numbers

 $ perl -e 'print "$_\n" for (1..10);'

May 30, 2017, 2:47 p.m.abhinickz6

1 score

List the content of a GitHub repository without cloning it

 $ svn ls https://github.com/user/repo/trunk/some/path

May 21, 2017, 6:01 p.m.Janos

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

2 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

5 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

1 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