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.

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:



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!

Top Tags





All commands from sorted by
Terminal - All commands - 12,177 results
source MYFILE.sql
2012-10-30 13:34:13
User: henry

This is a mysql command. So, first login with mysql -u name -p. Then "use DATABASE". Lastly, issue this command to import data.

python -c 'import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=4)' < file.yaml > file.json
2013-04-24 00:28:55
User: tebeka
Functions: python
Tags: python json yaml

Converts YAML file to JSON.

Note that you'll need to install PyYAML. Also some YAML data types (like dates) are not supported by JSON).

openssl pkcs8 -in /etc/pki/tls/web.key -out /root/wc.key -nocrypt && tshark -o "ssl.desegment_ssl_records:TRUE" -o "ssl.desegment_ssl_application_data:TRUE" -o "ssl.keys_list:,443,http,/root/wc.key" -o "ssl.debug_file:rsa.log" -R "(tcp.port eq 443)"
2013-07-06 08:01:36
User: ryanchapman

If on a web server (with access to the ssl key), decrypt SSL off the wire

rpm --query --filesbypackage [packagename]
ps -ef | grep user | awk '{print $2}' | while read pid; do echo $pid ; pfiles $pid| grep portnum; done
2010-01-11 12:34:51
User: sharfah
Functions: awk echo grep ps read

My old Solaris server does not have lsof, so I have to use pfiles.

netstat -in
acpi -b | sed 's/,//g' | awk '{print $3}'
2010-06-11 05:32:57
User: dbbolton
Functions: acpi awk sed
Tags: battery acpi

This prints "Charging" or "Discharging". Obviously, this will indicate the status of the AC adapter. The awk part could be from 1-6. I removed the comma because it is useless when only looking at one element of the output array. See acpi(1) for more info.

printf $(( echo "obase=16;$(echo $$$(date +%s%N))"|bc; ip link show|sed -n '/eth/ {N; p}'|grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'|head -c 17 )|tr -d [:space:][:punct:] |sed 's/[[:xdigit:]]\{2\}/\\x&/g')|sha1sum|head -c 32; echo
2010-07-14 14:04:53
User: camocrazed
Functions: echo grep head link printf sed tr
Tags: uuid

first off, if you just want a random UUID, here's the actual command to use:


Your chances of finding a duplicate after running this nonstop for a year are about the same as being hit by a meteorite before finishing this sentence

The reason for the command I have is that it's more provably unique than the one that uuidgen creates. uuidgen creates a random one by default, or an unencrypted one based on time and network address if you give it the -t option.

Mine uses the mac address of the ethernet interface, the process id of the caller, and the system time down to nanosecond resolution, which is provably unique over all computers past, present, and future, subject to collisions in the cryptographic hash used, and the uniqueness of your mac address.

Warning: feel free to experiment, but be warned that the stdin of the hash is binary data at that point, which may mess up your terminal if you don't pipe it into something. If it does mess up though, just type

TOTAL_RAM=`free | head -n 2 | tail -n 1 | awk '{ print $2 }'`; PROC_RSS=`ps axo rss,comm | grep [h]ttpd | awk '{ TOTAL += $1 } END { print TOTAL }'`; PROC_PCT=`echo "scale=4; ( $PROC_RSS/$TOTAL_RAM ) * 100" | bc`; echo "RAM Used by HTTP: $PROC_PCT%"
grep "$1" urls.txt | awk '{print "curl --write-out "$0"=http-%{http_code}\"\n\" --silent --output /dev/null "$0'} | sh >> responses.txt
ccd () { cd *$1*; }
2012-07-01 10:46:06
User: saturation
Functions: cd

If you have long and complicated folder names this might ease your work.

add this into .bashrc

command 3>&1 1>&2 2>&3 | tee -a file
2012-10-30 15:40:08
User: netkill
Functions: command tee

Appends output to the file, some systems require the -a to do this.

watch -n 1 'iostat -xmd 1 2'
2013-07-06 08:07:32
User: ryanchapman
Functions: watch
Tags: iostat

Shows a constantly updating display of disk IO activity. Two sections are in the output. The first is the IO activity since the machine was booted, the second section is the IO activity in the last second

ls -ls -tr | tail
read -p "Please enter the 4chan url: "|egrep '//i.4cdn.org/[a-z0-9]+/src/([0-9]*).(jpg|png|gif)' - -o|nl -s https:|cut -c7-|uniq|wget -nc -i - --random-wait
uname -p
qdbus org.kde.krunner_lock /MainApplication quit; qdbus org.kde.plasma-overlay /MainApplication quit
while true;do clear;echo -n Current\ `grep voltage /proc/acpi/battery/BAT0/state | awk '{print $2" "$3" "$4}'`;for i in `seq 1 5`;do sleep 1;echo -n .;done;done
tr -cs A-Za-z '\n' | sort | uniq -ci
2010-10-20 04:12:58
Functions: sort tr uniq
Tags: sort uniq tr

Gives the same results as the command by putnamhill using nine less characters.

finger | grep $(whoami) | head -n1 | awk '{print $2 " " $3}'
2011-01-07 16:54:11
User: mogoh
Functions: awk finger grep head

finger - gets logged in users

grep $(whoami) - greps only the current user (if there are more logged in)

head -n1 - just one line

awk '{print $2 " " $3}' - second and third word, seperated with a space (the users name)

OT: My first commandlinefu-command :)

for i in $(find . -type f); do mv "$i" "$(echo $i|tr A-Z a-z)"; done
gpg -e --default-recipient-self <SENSITIVE_FILE> && shred -zu "$_"
2011-07-24 05:51:47
User: h3xx
Functions: gpg shred
Tags: GPG shred

Make sure the file contents can't be retrieved if anyone gets ahold of your physical hard drive.

With hard drive partition:

gpg --default-recipient-self -o /path/to/encrypted_backup.gpg -e /dev/sdb1 && shred -z /dev/sdb1

WARNING/disclaimer: Be sure you... F&%k it--just don't try this.

mplayer -shuffle $HOME/music/* $HOME/music/*/* $HOME/music/*/*/* etc.
ls -l | sort +4n for ascending order or ls -l | sort +4nr for descending order
> file.txt
2012-08-24 06:51:13
User: arkanjo

Using only this, has the same.

(tested in linux, HP-UX and AIX)