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,590 results
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" ))
4

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); }
4

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); }
4

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
4

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'
smbget -u username -p passw0rd -w domain_or_workgroup //server/share/mediafile.ogv -O - | mplayer -
2014-02-16 21:42:06
User: dizzi90
0

add -rootwin to make it cover the whole desktop.

This may work better than mounting it as a cifs mount.

partx -l /dev/sdX
fdisk -l
sort in-file.txt | uniq -u > out-file.txt
du -g | perl -ne 'print if (tr#/#/# == <maximum depth>)'
2014-02-15 07:33:36
User: RAKK
Functions: du perl
Tags: perl du unix aix
0

Lists directory size up to a maximum traversal depth on systems like IBM AIX, where the du command doesn't have Linux's --max-depth option. AIX's du uses -g to display directory size on gigabytes, -m to use megabytes, and -k to use kilobytes. tr### is a Perl function that replaces characters and returns the amount of changed characters, so in this case it will return how many slashes there were in the full path name.

srm() { if [[ -d $1 ]]; then rm -R $1; else rm $1; fi }
tar --exclude='patternToExclude' --use-compress-program=pbzip2 -cf 'my-archive.tar.bz2' directoyToZip/
ps -eo etime,pid,pcpu,ppid,args | sed -e '/\[.\+\]/d' -e '/^[ \t]*[0-9]\{2\}:[0-9]\{2\} /d' | sort -k1r
2014-02-14 00:22:31
User: neurodrone
Functions: ps sed sort
0

If you have ever been trying to look for a list of processes based on their elapsed time you don't need to look any further.

This command lets you find the list of processes ordered in a reversed order (oldest at the top) that have been running for over an hour on your system. Any system processes are filtered out, leaving only user initiated ones in. I find it extremely useful for debugging and performance analysis.

cmd1 && cmd2 && echo success || echo epic fail
icacls directory_or_file /grant user_or_group:(OI)(CI)rx /t / l /q