Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.
Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Hide

Credits

All commands from sorted by
Terminal - All commands - 12,179 results
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
2015-01-25 00:30:37
User: krizzo
Functions: grep xargs
3

This checks if the branch has been merged with master and then will delete the ones that have been. Keeps your local git repo nice and clean from all the branches.

curl -XGET 'localhost:9200'
2015-01-23 15:01:29
User: paulera
1

Replace localhost:9200 with your server location and port. This is the ElasticSearch's default setup for local instances.

lsof -ns | grep REG | grep deleted | awk '{a[$1]+=$7;}END{for(i in a){printf("%s %.2f MB\n", i, a[i]/1048576);}}'
python -c 'import sys, yaml, json; yaml.safe_dump(json.load(sys.stdin), sys.stdout, allow_unicode=True)' < foo.json > foo.yaml
2015-01-20 15:58:29
User: renoirb
Functions: python
1

If you tried the other Python version of Convert JSON to YAML and you end up with lines that has "!!python/unicode", this version of the command is for you.

(pv -n centos-7.0-1406-x86_64-DVD.img | dd of=/dev/disk4 bs=1m conv=notrunc,noerror) 2>&1 | dialog --gauge "Copying CentOS to USB Stick in /dev/disk4" 10 70 0
hexdump -n6 -e '/1 ":%02X"' /dev/random|sed s/^://g
2015-01-19 03:09:43
User: rubo77
Functions: hexdump sed
3

Generate a random MAC address with capital letters

while ( true ) ; do if [ $(expr $RANDOM % 2 ) -eq 0 ] ; then echo -ne "\xE2\x95\xB1" ; else echo -ne "\xE2\x95\xB2" ; fi ; done
2015-01-17 12:46:37
User: tobi
Functions: echo expr true
1

Generates labyrinth-like pattern on UTF-8 terminal in bash.

For fun ;)

\[command]
2015-01-15 18:31:50
User: tyzbit
1

Most distributions alias cp to 'cp -i', which means when you attempt to copy into a directory that already contains the file, cp will prompt to overwrite. A great default to have, but when you mean to overwrite thousands of files, you don't want to sit there hitting [y] then [enter] thousands of times.

Enter the backslash. It runs the command unaliased, so as in the example, cp will happily overwrite existing files much in the way mv works.

ssh hostname nc -l 9876
svn propset svn:mergeinfo "/trunk:4" .
mkfifo fifo; while true ; do echo "Waiting for new event"; nc -l 8080 < fifo | tee -a proxy.txt /dev/stderr | nc 192.168.0.1 80 > fifo ; done
2015-01-14 09:26:54
User: ynedelchev
Functions: echo mkfifo tee true
5

If you have a client that connects to a server via plain text protocol such as HTTP or FTP, with this command you can monitor the messages that the client sends to the server. Application level text stream will be dumped on the command line as well as saved in a file called proxy.txt.

You have to change 8080 to the local port where you want your client to connect to. Change also 192.168.0.1 to the IP address of the destination server and 80 to the port of the destination server.

Then simply point your client to localhost 8080 (or whatever you changed it to).

The traffic will be redirected to host 192.168.0.1 on port 80 (or whatever you changed them to).

Any requests from the client to the server will be dumped on the console as well as in the file "proxy.txt".

Unfortunately the responses from the server will not be dumped.

if [ "${SSH_CLIENT%% *}" == "ipaddr" ]; then command; fi
2015-01-13 22:09:38
User: snipertyler
Tags: ssh
4

Place in ~/.bashrc

If you login to a ssh server from different ips, sometimes you want to do something specific for each.

e.g., quickly go into screen -x session from a phone, but not your desktop.

tar -cvj --exclude-vcs -f archive.tar.bz2 somedirectory
2015-01-13 14:55:41
User: fr00tyl00p
Functions: tar
0

You can create a backup of a directory which does not contain disturbing .svn and similar directories with that command.

xset -b
2015-01-13 14:45:24
User: fr00tyl00p
1

Execute this command in a terminal to disable the system-bell during X-session lifetime.

less -S somefile
ffmpeg -i "$fin" -c copy -copyts "${fin%.*}.mp4"
ssh-keygen -t rsa -b 4096 -f ~/.ssh/<ROLE>_rsa -C "Comment goes here"
2015-01-11 17:52:21
User: krizzo
Functions: ssh ssh-keygen
Tags: ssh-keygen
0

This is just a default ssh-keygen command. Prompts for a password that you can use to secure the keys more and uses a higher bit value than the default along with naming the key something other than id_rsa for better file identification.

avconv -i ka-ching.flv -acodec copy -vcodec copy ka-ching.mkv
printf "\e[7m%-`tput cols`s\e[0m\n" "Full width highlighted line"
2015-01-08 16:17:43
User: fr00tyl00p
Functions: printf
1

Show a full terminal line inverted with custom text.

zip -r /tmp/filename-`date +%Y%m%d_%H%M%S`.zip /directory/
find . -type f -exec echo -n "touch -t \`echo " \; -exec echo -n {} \; -exec echo -n " | sed -E 's/.*([[:digit:]]{8})_([[:digit:]]{4})([[:digit:]]{2}).*/\1\2.\3/g'\` " \; -exec echo {} \; | sh
clear;while true;sleep 1;do for((a=1;a<=$(tput cols)/3;a++));do tput cup 0 $a;echo " " $(date);done;sleep 1;for((a;a>=1;a--));do tput cup 0 $a;echo $(date) " ";done;done
cd(), do a ls (or whatever you can imagine) after a cd, func to long please refer to description
2015-01-01 20:50:19
User: Xk2c
Functions: cd ls
-6

some people on the net already use a cd(), but most of them break 'cd -' functionality,

that is "go back where you have been previosly", or 'cd' which is "go back home".

This cd() copes with that. Also when given a file name, go to the directory where this file is in.

cd()

{

if [[ -n ${*} ]]

then

if [[ s${*}e == s-e ]]

then

builtin cd -

elif [[ ! -d ${*} ]]

then

builtin cd "${*%/*}"

else

builtin cd "${*}"

fi

else

builtin cd ~

fi

ls -la

}

[ ~/temp/foo/bar/baz ] $ .. 3
2015-01-01 20:41:17
User: Xk2c
-4

many have aliases like:

alias ...="cd ../../"

alias ....="cd ../../../"

and so furth.

..() mitigates to need for those aliases, see sample output for an example

# .. -> go up 1 directory

# .. 4 -> go up 4 directories

..()

{

local DIR=''

declare -i NUM=0

if [[ ${1} =~ ^[1-9][0-9]*$ ]]

then

while (( ${NUM} < ${1:-1} ))

do

DIR="${DIR}../"

NUM=$(( ${NUM} + 1 ))

done

else

DIR=..

fi

cd "${DIR}"

}