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
lsof -Pan -i tcp -i udp
2010-06-07 15:22:44
User: atoponce
Tags: netstat lsof

This command is more portable than it's cousin netstat. It works well on all the BSDs, GNU/Linux, AIX and Mac OS X. You won't find lsof by default on Solaris or HPUX by default, but packages exist around the web for installation, if needed, and the command works as shown. This is the most portable command I can find that lists listening ports and their associated pid.

vi +/pattern [file]
2010-04-24 22:15:12
User: punkwalrus
Functions: vi
Tags: vim edit vi

Open up vi or vim at the first instance of a pattern in [file]. Useful if you know where you want to be, like "PermitRootLogin" in sshd_config. Also, vi +10 [file] will open up a file at line 10. VERY useful when you get "error at line 10" type of output.

apt-get install most && update-alternatives --set pager /usr/bin/most
2010-01-04 14:13:55
User: aurium
Functions: apt install

That command installs "most" and make this command as the default man reader. The "most" works like "less" (the current man reader), but it render colors for manpages and may do more things. Read "man most".

You can see a preview here: http://www.dicas-l.com.br/dicas-l/20090718.php

yes | pv | ssh $host "cat > /dev/null"
2009-12-27 21:34:23
User: opertinicy
Functions: ssh yes
Tags: ssh yes pv

connects to host via ssh and displays the live transfer speed, directing all transferred data to /dev/null

needs pv installed

Debian: 'apt-get install pv'

Fedora: 'yum install pv' (may need the 'extras' repository enabled)

some_command > >(/bin/cmd_for_stdout) 2> >(/bin/cmd_for_stderr)
2009-12-01 03:58:04
User: tylerl

You can use [n]> combined with >(cmd) to attach the various output file descriptors to be the input of different commands.

( ( sleep 2h; your-command your-args ) & )
2009-08-19 17:39:11
User: sitaram
Functions: sleep

doesn't require "at", change the "2h" to whatever you want... (deafult unit for sleep is seconds)

cd !$:h
2009-08-07 00:37:08
User: lingo
Functions: cd

Uses the last argument of the last executed command, and gets the directory name from it.

Use $!:t for the filename alone, without the dirname.

perl -e 'print "P1\n256 256\n", map {$_&($_>>8)?1:0} (0..0xffff)' | display
2009-07-08 17:50:23
User: dstahlke
Functions: perl

OK, not the most useful but a good way to impress friends. Requires the "display" command from ImageMagick.

lsof -c dhcpd
2009-04-17 07:18:38
User: d4n3sh

List all file opened by a particular command based on it's command name.

curl -Is slashdot.org | egrep '^X-(F|B|L)' | cut -d \- -f 2
lynx -accept_all_cookies -cmd_script=/your/keystroke-file
2009-03-17 00:38:36
User: Alanceil

This command will tell lynx to read keystrokes from the specified file - which can be used in a cronjob to auto-login on websites that give you points for logging in once a day *cough cough* (which is why I used -accept_all_cookies).

For creating your keystroke file, use:

lynx -cmd_log yourfile
$ grep -rl oldstring . |xargs sed -i -e 's/oldstring/newstring/'
2009-03-03 20:10:19
User: netfortius
Functions: grep sed
Tags: perl sed

recursively traverse the directory structure from . down, look for string "oldstring" in all files, and replace it with "newstring", wherever found


grep -rl oldstring . |xargs perl -pi~ -e 's/oldstring/newstring'
xset dpms force standby
netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c
ssh remotehost 'dpkg --get-selections' | dpkg --set-selections && dselect install
2011-05-12 17:26:43
User: Mozai
Functions: ssh

(also works on Ubuntu) Copies the 'install,' 'hold,' 'deinstall' and 'purge' states of packages on the remote machine to be matched on the local machine. Note: if packages were installed on the local machine that were never installed on the remote machine, they will not be deinstalled by this operation.

file -s /dev/sd*
2010-12-28 09:56:03
User: mhs
Functions: file
Tags: file devfs

file(1) can print details about certain devices in the /dev/ directory (block devices in this example). This helped me to know at a glance the location and revision of my bootloader, UUIDs, filesystem status, which partitions were primaries / logicals, etc.. without running several commands.

See also:

file -s /dev/dm-* file -s /dev/cciss/*


rm *.txt <TAB> <TAB>
2010-11-04 13:58:15
User: boschi
Functions: rm

alternative for "echo rm *.txt". Just doubletab the command you are willing to use and it will show you the affected files.

PROMPT_COMMAND='if [ $RANDOM -le 3200 ]; then printf "\0337\033[%d;%dH\033[4%dm \033[m\0338" $((RANDOM%LINES+1)) $((RANDOM%COLUMNS+1)) $((RANDOM%8)); fi'
2010-04-01 06:52:32
User: hotdog003
Functions: printf
Tags: bash

Add this to a fiend's .bashrc.

PROMPT_COMMAND will run just before a prompt is drawn.

RANDOM will be between 0 and 32768; in this case, it'll run about 1/10th of the time.

\033 is the escape character. I'll call it \e for short.

\e7 -- save cursor position.

\e[%d;%dH -- move cursor to absolute position

\e[4%dm \e[m -- draw a random color at that point

\e8 -- restore position.

<ESC> .
xkcd(){ wget -qO- http://xkcd.com/|tee >(feh $(grep -Po '(?<=")http://imgs[^/]+/comics/[^"]+\.\w{3}'))|grep -Po '(?<=(\w{3})" title=").*(?=" alt)';}
2009-11-27 09:11:47
User: eightmillion
Functions: grep tee wget

This function displays the latest comic from xkcd.com. One of the best things about xkcd is the title text when you hover over the comic, so this function also displays that after you close the comic.

To get a random xkcd comic, I also use the following:

xkcdrandom(){ wget -qO- dynamic.xkcd.com/comic/random|tee >(feh $(grep -Po '(?<=")http://imgs[^/]+/comics/[^"]+\.\w{3}'))|grep -Po '(?<=(\w{3})" title=").*(?=" alt)';}
read -sn 1 -p "Press any key to continue..."
clfavs(){ URL="http://www.commandlinefu.com";wget -O - --save-cookies c --post-data "username=$1&password=$2&submit=Let+me+in" $URL/users/signin;for i in `seq 0 25 $3`;do wget -O - --load-cookies c $URL/commands/favourites/plaintext/$i >>$4;done;rm -f c;}
2009-09-30 16:43:08
User: suhasgupta
Functions: c++ wget

Usage: clfavs username password num_favourite_commands file_in_which_to_backup

tar -cj /backup | cstream -t 777k | ssh host 'tar -xj -C /backup'
2009-07-02 10:05:53
User: wires
Functions: host ssh tar

this bzips a folder and transfers it over the network to "host" at 777k bit/s.

cstream can do a lot more, have a look http://www.cons.org/cracauer/cstream.html#usage

for example:

echo w00t, i'm 733+ | cstream -b1 -t2

hehe :)

./my-really-long-job.sh && notify-send "Job finished"
2009-05-07 15:50:27
User: root
Tags: notify-send

You will need libnotify-bin for this to work:

sudo aptitude install libnotify-bin
bash -x ./post_to_commandlinefu.sh