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.

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



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,394 results
CMD=chrome ; ps h -o pmem -C $CMD | awk '{sum+=$1} END {print sum}'
nohup gnome-open . 0</dev/null 1>/dev/null 2>/dev/null&
2010-03-22 07:19:37
User: drunkcoder
Functions: nohup

this will open the current directory in nautilus detached from your terminal.

cat input.txt | sed 's/\\\033[^a-zA-Z]*.//g'
2011-10-13 14:46:03
User: evolix

Permit to generate a password for userPassword in ldap.

Use ?slappasswd -g? to generate a random passowrd.

perl -ne 's/\^.{1,7}?m//g;print'
2012-01-02 01:32:33
User: Tracerneo
Functions: perl
Tags: perl regex colors

Removes special characters (colors) in '^]]Xm' and '^]]X;Ym' format from file.

Use pipe ('input | perl [...]') or stream ('perl [...]

You can use 'cat -v infile' as 'input' to show special characters instead of interpreting (there is problem with non-ASCII chars, they are replaced by M-[char]).

awk '{pattern=$1$2; seen[pattern]++; if (seen[pattern] == 1) print NR}' inputFile
ps awwux|awk '{print $1}'|sort|uniq
gem list | cut -d" " -f1 | grep --invert-match "test-unit\|psych\|io-console\|rdoc\|json\|bigdecimal\|rake\|minitest" | xargs gem uninstall -aIx
2014-01-10 10:58:59
User: gdelfino
Functions: cut grep xargs

This command removes all ruby gems except the default ones that can not be removed. It is based on http://geekystuff.net/2009/01/14/remove-all-ruby-gems/

WID=xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| awk '{print $5}' xdotool windowfocus $WID xdotool key ctrl+shift+t wmctrl -i -a $WID
2010-03-22 08:34:24
User: drunkcoder
Functions: awk grep

open a new tab in active gnome-terminal instance

needs sudo apt-get install xdotool

and sudo apt-get install wmctrl

sed -i 's/\r\n//' file.txt
perl -MModule::Name\ 9999 -e 1
2013-01-15 22:51:39
User: three18ti
Functions: perl
Tags: bash perl zsh

This attempts to load a Perl Module (-M flag) and use version 9999, since no module has a version this high, Perl exits either a) telling you the version of the module installed or b) tells you it can't find the module.

hgrep() { ... } longer then 255 characters, see below
2014-04-02 16:40:36
User: Xk2c



if [[ ${#} -eq 0 ]]


printf "usage:\nhgrep [--nonum | -N | -n | --all-nonum | -an | -na] STRING\n"

return 1


while [[ ${#} -gt 0 ]]


case ${1} in

--nonum | -N | -n | --all-nonum | -an | -na)

builtin history | sed 's/^[[:blank:]]\+[[:digit:]]\{1,5\}[[:blank:]]\{2\}//' | grep -iE "(${*:2})"




builtin history | grep -iE "(${*})"






'hgrep -n' helps in using full grep support, e.g. search for _beginning_ of specific commands,

see example output

du -sm *|sort -rn|head -10
season=1; for file in $(ls) ; do dir=$(echo $file | sed 's/.*S0$season\(E[0-9]\{2\}\).*/\1/'); mkdir $dir ; mv $file $dir; done
2009-05-27 03:30:58
User: lonecat
Functions: echo file mkdir mv sed

It happened to me that I got a season of a tv-show which had all files under the same folder like /home/blah/tv_show/season1/file{1,2,3,4,5,...}.avi

But I like to have them like this:


So I can have both the srt and the avi on one folder without cluttering much. This command organizes everything assuming that the filename contains Exx where xx is the number of the episode.

You may need to set:


if your filenames have spaces.

xwinwrap -ni -argb -fs -s -st -sp -nf -b -- /usr/libexec/xscreensaver/atlantis -count 20 -window-id WID &
2009-09-23 05:29:21
User: dstahlke
Tags: xwinwrap

xwinwrap allows you to run any program in the root desktop pane. I like to run atlantis, it goes well against Fedora 10's blue sun background. At one time this also served a useful purpose for me as a workaround for a problem that would happen when the video card went into sleep mode.

wget -O xkcd_$(date +%y-%m-%d).png `lynx --dump http://xkcd.com/|grep png`; eog xkcd_$(date +%y-%m-%d).png
awk -vRS="</Tag2>" '/<Tag2>/{gsub(/.*<Tag2>/,"");print}' file
while true; do /bin/ping -q -c1 -w3 2>&1 > /dev/null || echo " ping failed at $(date +%d/%m/%y) $(date +%H:%M:%S)" >> /var/log/ping.log; sleep 10; done &
2011-05-12 01:51:07
User: Arkey
Functions: echo sleep

This command are using by me for checking connection with Internet.

fping -g -r 1 | grep -v unreachable | awk '{print $1}'
Find files that have been changed by a Chef run today.
$ apg -m 40 -a 1
2013-07-26 14:13:49
User: blz

apg generates several random passwords. It uses several password generation algorithms (currently two) and a built-in pseudo random number generator.

find -L /home/sonic/archive -name '*gz' -type f
2013-10-07 14:32:22
User: sonic
Functions: find
Tags: find

If /home/sonic/archive/ was a symlink to /backup/sonic/archive it would follow the links and give you the file listing. By default find will NOT follow symbolic links. The default behavior for the find command is to treat the symlinks as literal files.

I discovered this when trying to write a script run via cron to delete files with a modification time older than X days. The easiest solution was to use:

/usr/bin/find -L /home/sonic/archive -name '*gz' -type f -mtime +14 -exec rm '{}' \;

IFS=$(echo -en "\n\b"); mkdir Epub; for i in `find . | grep epub`; do echo "epub: $i"; mv -v "$i" Epub; done
C:\> shutdown /f /r /t 0
2014-04-02 22:35:00
User: mpb
Functions: shutdown

Today, I needed to reboot a Windoze machine on another continent which had no shutdown or restart options via "Start" in the remote desktop (the only options available were: "Logoff, Disconnect, or Lock").

Fortunately, I found how to shutdown and restart from the command line.