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.


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.

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

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.
Hide

Tags

Hide

Functions

Commands using man from sorted by
Terminal - Commands using man - 61 results
man $(/bin/ls /bin | awk '{ cmd[i++] = $0 } END { srand(); print cmd[int(rand()*length(cmd))]; }')
2010-08-20 17:31:02
User: emilsit
Functions: awk man
Tags: man awk
-4

Build an awk array with all commands and then select a random one at the end.

This avoids spawning extra processes for counting with wc or generating random numbers.

Explicitly call /bin/ls to avoid interactions with aliases.

(cd /bin; set -- *; x=$((1+($RANDOM % $#))); man ${!x})
man $(ls /bin | sed -n $((RANDOM % $(ls /bin | wc -l) + 1))p)
2010-08-20 17:15:33
User: putnamhill
Functions: ls man sed wc
Tags: man sed ls wc random
-2

Great idea camocrazed. Another twist would be to display a different man page based on the day of the year. The following will continuously cycle through all man pages:

man $(ls /bin | sed -n $(($(date +%j) % $(ls /bin | wc -l)))p)
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
-2

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
8

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
-2

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
0

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
0

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
4

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
-7

A very interesting man page!

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

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
1

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
2

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
14

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
-11

Display man page in plain text

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

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
0

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
0

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
0

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
3

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.