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.


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:



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.




Commands using man from sorted by
Terminal - Commands using man - 58 results
dir="/bin"; man $(ls $dir |sed -n "$(echo $(( $RANDOM % $(ls $dir |wc -l | awk "{ print $1; }" ) + 1 )) )p")
2010-08-20 16:31:50
User: camocrazed
Functions: dir ls man sed
Tags: man sed awk echo wc

Broaden your knowledge of the utilities available to you in no particular order whatsoever! Then use that knowledge to create more nifty one-liners that you can post here. =p

Takes a random number modulo the number of files in $dir, prints the filename corresponding to that number, and passes it as an argument to man.

man !!:0
2010-08-14 15:38:55
User: stubby
Functions: man

This works in bash. The "!!:0" limits the argument to man to be only the first word of the last command. "!!:1" would be the second, etc.

man !!
for file in $(ls /usr/bin ) ; do man -w $file 2>> nomanlist.txt >/dev/null ; done
2010-07-26 19:39:53
User: camocrazed
Functions: file ls man
Tags: man

This takes quite a while on my system. You may want to test it out with /bin first, or background it and keep working.

If you want to get rid of the "No manual entry for [whatever]" and just have the [whatever], use the following sed command after this one finishes.

sed -n 's/^No manual entry for \(.*\)/\1/p' nomanlist.txt
for i in {a..z} ; do man -k $i |grep -i "^$i" |wc | awk 'BEGIN { OFS = ":"; ORS = "" }{print $1, "\t"}' && echo $i ;done
function mg(){ man ${1} | egrep ${2} | more; }
2010-07-01 21:14:24
User: quincymd
Functions: egrep man
Tags: man grep

Quicker way to search man pages of command for key word

addman () { export MANPATH=`find $1 -xdev -type d -name man -printf %p:`${MANPATH}; }
2010-06-12 17:47:20
User: zoomgarden
Functions: export man
Tags: man function

Prepends paths containing man directories to your MANPATH variable for the given top level directory. If you build or install software with non-standard documentation locations, you can just add them to your MANPATH with this little function. -xdev prevents crossing filesystem boundaries when searching for man dirs.

man intro
2010-02-17 10:11:56
User: peppet
Functions: man

Tested on debian and ubuntu. Translations could be useless, so "LANG=C man intro" is a better alternative.

man ettercap
2010-01-29 14:28:38
User: Abiden
Functions: man

A very interesting man page!

man <COMMAND> | less +'/pattern'
man hier
2010-01-26 16:31:05
User: haivu
Functions: man

Curious about differences between /bin, /usr/bin, and /usr/local/bin? What should be in the /sbin dir? Try this command to find out.

Tested against Red Hat & OS X

LC_ALL=C man -c man
2010-01-07 00:59:09
User: bhepple
Functions: man

Often you find some tty programs are messed up and confused about character encoding - 'man' is a common problem and sometimes displays weird characters for apostrophes, hyphens etc etc. Another class of programs that suffer from this are those that try to use the line drawing characters - eg RedHat's tty system admin functions such as system-config-firewall-tui system-config-network-tui etc.

Adding 'LC_ALL=C' fixes most of these problems (as long as you want English! Perhaps speakers of other languages can add a comment here).

For bonus points, I've added the '-c' option to the man command so that it ignores it's cache and re-computes the man page using the C locale.

/usr/bin/man man | /usr/bin/col -b | /usr/bin/iconv -c | view -c 'set ft=man nomod nolist nospell nonu
2010-01-04 18:35:42
User: furicle
Functions: man

Colourful with vim regex finding goodness!

Replace the 'man' with the page to be looked up.

I actually have as a function in my .profile

function vman {

/usr/bin/man $* | /usr/bin/col -b | /usr/bin/iconv -c | view -c 'set ft=man nomod nolist nospell nonu' -

function man2pdf(){ man -t ${1:?Specify man as arg} | ps2pdf -dCompatibility=1.3 - - > ${1}.pdf; }
2009-11-27 12:49:49
User: SuperFly
Functions: as man

Tested on Fedora 12. This function will take a man page and convert it to pdf, saving the output to the current working directory. In Gnome, you can then view the output with "gnome-open file.pdf", or your favorite pdf viewer.

man bash | col -b
2009-09-10 00:45:27
User: suxer
Functions: bash col man

Display man page in plain text

man 5 crontab
2009-09-03 19:27:08
User: 0disse0
Functions: man

You can view the man pages from section five by passing the section number as an argument to the man command

man -t man | ps2pdf - > man.pdf
man -P cat ls > man_ls.txt
2009-07-27 13:09:24
User: alvinx
Functions: cat ls man

Output manpage as plaintext using cat as pager: man -P cat commandname

And redirect its stdout into a file: man -P cat commandname > textfile.txt

Example: man -P cat ls > man_ls.txt

man perlcheat | col -b > perlcheat.txt
man -Tps ls >> ls_manpage.ps && ps2pdf ls_manpage.ps
2009-07-05 09:31:36
User: 0x2142
Functions: ls man
Tags: man pdf

Creates a PDF (over ps as intermediate format) out of any given manpage.

Other useful arguments for the -T switch are dvi, utf8 or latin1.

man fetchmail | perl -ne 'undef $/; print $1 if m/^.*?(-k \| --keep.*)-K \| --nokeep.*$/smg'
2009-06-25 23:51:35
Functions: fetchmail man perl

Using perl, here, we grep the man page of fetchmail to find the paragraph starting with '-k | --keep' and ending before the paragraph starting with '-K | --nokeep'

find `echo "${PATH}" | tr ':' ' '` -type f | while read COMMAND; do man -f "${COMMAND##*/}"; done
2009-06-13 19:56:24
User: mohan43u
Functions: find man read tr
Tags: man find read while tr

Obviously, you can replace 'man' command with any command in this command line to do useful things. I just want to mention that there is a way to list all the commands which you can execute directly without giving fullpath.

Normally all important commands will be placed in your PATH directories. This commandline uses that variable to get commands. Works in Ubuntu, will work in all 'manpage' configured *nix systems.

man ls | col -b > ~/Desktop/man_ls.txt
2009-06-13 11:49:33
User: vigo
Functions: col ls man

You can convert any UNIX man page to .txt

man beep | sed -e '1,/Note/d; /BUGS/,$d' | awk '{print $2}' | xargs -IX sudo beep -f X -l 500
2009-04-01 06:48:48
User: jnash
Functions: awk man sed sudo xargs

Are there any creative pieces of music that can be created using beep and the shell? I'd love to hear it!

for i in $(seq 1 11) 13 14 15 16; do man iso-8859-$i; done
2009-03-31 19:40:15
User: penpen
Functions: man seq
Tags: Linux unix

Depending on the installation only certain of these man pages are installed. 12 is left out on purpose because ISO/IEC 8859-12 does not exist. To also access those manpages that are not installed use opera (or any other browser that supports all the character sets involved) to display online versions of the manpages hosted at kernel.org:

for i in $(seq 1 11) 13 14 15 16; do opera http://www.kernel.org/doc/man-pages/online/pages/man7/iso_8859-$i.7.html; done