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.

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

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 12,019 results
aptitude --purge remove ~i^foo ~i^bar
2015-01-27 15:00:48
User: mhs
Tags: aptitude
1

Could be dangerous, if you have many packages all beginning with 'foo' or 'bar'. This will easily remove them all from your system.

xset b 50 1700 10
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
1

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
3

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