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 - 11,492 results
watch -d -n 2 iptables -nvL
2014-02-23 16:35:03
User: xxdesmus
Functions: iptables watch
0

This will highlight (with a box over it) any changes since the last refresh.

ps -eo pmem,comm | grep application-name
2014-02-23 13:21:29
User: Darkstar
Functions: grep ps
0

Displays memory usage for individual instances of an application that spawns multiple instances of itself. This command also works on single process applications.

alias ...="awk '{fflush(); printf \".\"}' && echo \"\""
2014-02-22 22:20:22
User: lgarron
Functions: alias
7

If you're running a command with a lot of output, this serves as a simple progress indicator.

This avoids the need to use `/dev/null` for silencing. It works for any command that outputs lines, updates live (`fflush` avoids buffering), and is simple to understand.

sed -i '1iI am a new line' file.txt
2014-02-22 14:36:57
User: bbates
Functions: sed
0

You can use \n in your inserted data to insert multiple lines.

The leading number is the position in the file where you want the insert, so in this case a '1' indicates the top of the file.

$(eval "echo {${min}..${max}}")
echo "select a, b, c from table where a = 3;"| python -c "import sys;import sqlparse;print sqlparse.format(sys.stdin.read(), reindent=True, keyword_case='upper')"
2014-02-21 23:17:15
User: hide1713
Functions: echo python
0

You need to apt-get install python-sqlparse. This command simply formats a sql query and prints it out. It is very useful when you want to move a sql query from commandline to a shell script. Everything is done locally, so you don't need to worry about copying sql query to external websites.

cp filename{,.`date +%Y%m%d-%H%M%S`}
2014-02-21 10:21:28
User: techtonik
Functions: cp
0

This inserts timestamp instead of .bak extension.

echo -n text | hexdump -C
2014-02-21 09:15:15
User: Tomofumi
Functions: echo hexdump
Tags: sed hex ascii
0

hexdump could be used for conversion too!

apt-get update -y && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get autoremove -y && apt-get autoclean -y
echo -n "string" | md5sum|cut -f 1 -d " "
2014-02-20 22:44:00
User: labadf
Functions: cut echo
0

echo defaults to include a newline character at the end of the string, which messes with the hash. If you suppress it with -n then it has the same effect as PHP's ?echo md5("string"), "\t-";? Even more, by using cut you get the exact same output, so it works as a drop-in replacement for the original command for this thread.

unzip -p doc.odt content.xml | sed 's|<[^>]*>| |g' | wc -l
sudo lsof -i -n -P | grep TCP
ab -n 1000 -c 100 http://127.0.0.1:8000/
2014-02-18 09:32:01
User: ynedelchev
1

This command will execute 1000 requests to the http URL http://127.0.0.1:8000 handlink 100 concurent connections at a time. Then it will display statistics about the time that have been taken.

udevadm info -q all -n /dev/sdb | grep ID_PATH | cut -d'-' -f 2 | xargs -n 1 lspci -s
echo "Memory:" $(dmidecode --type memory | grep " MB" | awk '{sum += $2; a=sum/1024} END {print a}') "GB"
(read -r passphrase; b58encode 80$( brainwallet_exponent "$passphrase" )$( brainwallet_checksum "$passphrase" ))
3

A bitcoin "brainwallet" is a secret passphrase you carry in the "wallet" of your brain.

The Bitcoin Brainwallet Private Key Calculator calculates the standard base58 encoded bitcoin private key from your "brainwallet" passphrase.

The private key is the most important bitcoin number. All other numbers can be derived from it.

This command uses 3 other functions - all 3 are defined on my user page:

1) brainwallet_exponent() - search for Bitcoin Brainwallet Exponent Calculator

2) brainwallet_checksum() - search for Bitcoin Brainwallet Exponent Calculator

3) b58encode() - search for Bitcoin Brainwallet Base58 Encoder

Do make sure you use really strong, unpredictable passphrases (30+ characters)!

http:brainwallet.org can be used to check the accuracy of this calculator.

function b58encode () { local b58_lookup_table=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z}); bc<<<"obase=58;ibase=16;${1^^}"|(read -a s; for b58_index in "${s[@]}" ; do printf %s ${b58_lookup_table[ 10#"$b58_index" ]}; done); }
3

A bitcoin "brainwallet" is a secret passphrase you carry in your brain.

The Bitcoin Brainwallet Private Key Base58 Encoder is the third of three functions needed to calculate a bitcoin PRIVATE key from your "brainwallet" passphrase.

This base58 encoder uses the obase parameter of the amazing bc utility to convert from ASCII-hex to base58. Tech note: bc inserts line continuation backslashes, but the "read s" command automatically strips them out.

I hope that one day base58 will, like base64, be added to the amazing openssl utility.

function brainwallet_checksum () { (o='openssl sha256 -binary'; p='printf';($p %b "\x80";$p %s "$1"|$o)|$o|sha256sum|cut -b1-8); }
3

A bitcoin "brainwallet" is a secret passphrase you carry in your brain.

The Bitcoin Brainwallet Exponent Calculator is the second of three functions needed to calculate a bitcoin PRIVATE key. Roughly, checksum is the first 8 hex digits of sha256(sha256(0x80+sha256(passphrase)))

Note that this is a bash function, which means you have to type its name to invoke it

function brainwallet_exponent () { printf %s "$1"|sha256sum|head -c 64; }
2014-02-18 01:49:09
User: nixnax
Functions: head printf
3

A bitcoin "brainwallet" is a secret passphrase you carry in your brain.

The Bitcoin Brainwallet Exponent Calculator is one of three functions needed to calculate the bitcoin PRIVATE key. Roughly, the formula is exponent = sha256 (passphrase)

Note that this is a bash function, which means you have to type its name to invoke it.

You can check the accuracy of the results here http://brainwallet.org

find . -exec chmod o+rx {}\;
for i in $(pip freeze | awk -F== '{print $1}'); do pip uninstall $i; done
2014-02-17 21:38:49
User: maurobaraldi
Functions: awk
0

If you creates a virtualenv just for a test, and at the end, wants remove all installed packages. This is the lever.

dmidecode --type memory
2014-02-17 12:15:07
User: c0r3dump3d
2

To take information about the characteristics of the installed memory modules.

find . -exec grep -Hn what \{\} \; | less
2014-02-17 09:59:01
User: ynedelchev
Functions: find grep what
0

This command will traverse all of the folders and subfolders under current working directory. For every file inside it, it will do a search inside the content of the file for a specific term 'what'. Then it will print a list of the lines that contain that term (and match that pattern). Each matching line will be preceded with the path and name to the file and then the line number iside taht file wehre the pattern was found. Then the actual content of the matching lien will be printed.

The output will be piped throug less, so that the user can scroll through it if it goes beyond the limits of the current display window.

$ screen -S test -d -m -- sh -c 'date; exec $SHELL'
2014-02-17 08:11:45
User: awek
Functions: exec screen sh test
0

The command creates new session "test", executes 'date' and then start your default shell (to keep the detached session alive). Change 'date' to fit your needs.

screen -r test

will attach the created session.

find . -name *.properties -exec /bin/echo {} \; -exec cat {} \; | grep -E 'listen|properties'