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.


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

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,361 results
FILE=$(tempfile 2>/dev/null || echo .$RANDOM)
2011-06-22 15:12:21
User: h3nr1x
Functions: echo
0

Another way to create temp files in your scripts, if tempfile fails, it will create a hidden local file in the current directory, don't forget to delete $FILE

lynx -dump http://example.com/ | awk '/http/{print $2}' | sort -u
2011-10-13 09:49:36
User: mathias
Functions: awk sort
Tags: awk lynx
0

This will get all links from a given URL, remove any duplicates, and output the result.

curl -s ifconfig.me|tee >(xargs geoiplookup)
2012-02-09 20:30:26
Functions: tee xargs
Tags: tee curl geoip
0

Show external IP and geolocation information.

Primary feature is the use of tee to echo IP _and_ send to geoiplookup command...Use IP as input for as many commands as you want with more >( [command] )

Thanks to http://www.commandlinefu.com/commands/view/6334/

Requires MaxMind DB and geoiplookup tool.

Sample output has IP obfuscated on first line, lines 2-4 from having MaxMind Country && MaxMind City DBs installed

grep -hor ofx[a-zA-Z]*.h src/ | grep -o ofx[^\.]* >> addons.make
wpa_passphrase "ESSID" "Password" | wpa_supplicant -Dwext -iwlan0 -c/dev/stdin&
2013-05-07 11:05:50
User: adamrights
0

If you need to hop on a wifi fast, perhaps you're fixing a system and it's read-only this command pipes the output of wpa_passphrase used to generate a .conf file and instead reads it from the standard input stream.

The -i switch for interface may not be wlan0, as udev will change it. A quick "ifconfig" or "dmesg | grep wlan0" will show you the wireless interface name.

amixer -c 0 set Master 1dB+
2013-07-25 15:28:45
User: chrisp6825
Functions: amixer set
0

adjusts the 'Master' channel's volume up by 1dB.

Can use command 'amixer' to see other channels :

Simple mixer control 'Master',0

or

Simple mixer control 'Capture',0

rvm --default use ruby-1.9.3
thunderbird -compose "attachment='file://`pwd`/$*'"
php -r 'echo json_encode( unserialize( file_get_contents( "php://stdin" ) ) );'
for file in `find /var/log/ -type f -size +5000k`; do > $file; done
2009-07-03 17:38:21
User: svg
Functions: file
0

you don't need to echo, just a plain redirect is enough to empty the file

find ./ -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1
2009-11-19 06:05:36
User: jnash
Functions: cut file find grep xargs
0

Uses mime-type of files rather than relying on file extensions to find files of a certain type.

This can obviously be extended to finding files of any other type as well.. like plain text files, audio, etc..

In reference to displaying the total hours of video (which was earlier posted in command line fu, but relied on the user having to supply all possible video file formats) we can now do better:

find ./ -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1 | xargs -d'\n' /usr/share/doc/mplayer/examples/midentify | grep ID_LENGTH | awk -F "=" '{sum += $2} END {print sum/60/60; print "hours"}'
gopyrit () { if [ $# -lt 1 ]; then echo $0 '< list of ESSIDs >'; return -1; fi; for i in "$@"; do pyrit -e $i create_essid && pyrit batch; done; pyrit eval }
2010-06-19 01:11:00
User: meathive
Functions: echo eval return
0

This command will automate the creation of ESSIDs and batch processing in pyrit. Give it a list of WPA/WPA2 access points you're targeting and it'll import those ESSIDs and pre-compute the potential password hashes for you, assuming you've got a list of passwords already imported using:

pyrit -i dictionary import_passwords

Once the command finishes, point pyrit to your packet capture containing a handshake with the attack_db module. Game over.

perl -e "tr/[A-Z]/[a-z]/;" -pi.save $(find . -type f)
perl -e 'printf join ".", map int rand 256, 1 .. 4;'
geoip() { lynx -dump "http://api.hostip.info/get_html.php?ip=$1&position=true"; }
0

Defines a function to geolocate a given IP address; if none supplied, will default to your external IP address.

perl -MAcme::POE::Tree -e 'Acme::POE::Tree->new()->run()'
IMG="image.img";PART=1;mount -o loop,ro,offset=$(parted $IMG -s unit b print|awk '$1=='$PART' {sub(/B/,"",$2);print $2}') $IMG /mnt/whatever
2011-12-31 14:58:18
User: AndroTux
Functions: awk mount
0

Mounts a disk-image of a hdd with partitions

import unicodedata; map(unicodedata.name, '\u2022'.decode('ascii'))
paste -sd, <<< $'line1\nline2'
2012-11-13 01:26:05
User: kodango
Functions: paste
Tags: paste
0

A more simple way to join lines with paste command than sed.

cut -f 2 -d ':' oclHashcat.pot | egrep -oi '[a-z]{1,20}' | sort | uniq > base.pot
mencoder -speed 2 -o output.avi -ovc lavc -oac mp3lame input.avi
exiv2 -M"set Exif.Photo.DateTimeOriginal `date "+%Y:%m:%d %H:%M:%S"`" filename.jpg
equery s | sed 's/(\|)/ /g' | sort -n -k 9 | gawk '{print $1" "$9/1048576"m"}'
2009-07-30 01:12:10
User: Alanceil
Functions: gawk sed sort
0

On a Gentoo system, this command will tell you which packets you have installed and sort them by how much space they consume. Good for finding out space-hogs when tidying up disk space.

`ls`
2009-08-17 03:56:05
User: matthewbauer
Tags: wildcard
0

This is exactly the same as a wildcard - good for times when wildcards are disabled and when you want have a wildcard of a directory that is not your current ({`ls /path/to/dir`}). Does not work on older versions of Bash though.

perl -le 'use Config; foreach $i (keys %Config) {print "$i : @Config{$i}"}'
2009-09-22 22:14:21
User: chuckr
Functions: perl
Tags: perl
0

This dumps all of your installed perl's config information.