Make The ‘man’ Command More Useful In Linux And OS X

The man command in Linux and OS X is great for learning more about Terminal commands, but doesn’t work for everything. Lifehacker reader undecim shares a shortcut that will make man more useful for certain commands.

If you have been trying to use the command line, you should know about the man command, which gives you instructions on what a certain command does (e.g. man ls will tell you all about the ls command). However, the manual doesn’t have information on every command. For example, on Ubuntu, there is no manual for the if command. This is a function built into the command line, and so it’s not a separate program like most. You can get information on it with the help command that is also built into the command line.

For convenience, you can make help a fallback for man. All you have to do is add this to the end of your .bashrc file in your home directory (Mac OS X Snow Leopard users, this file is called .bash_profile):

man () {
/usr/bin/man $@ || (help $@ 2> /dev/null && help $@ | less)
}

Then either restart your command line, or run . .bashrc to re-load the file.

This overrides the man command. It calls the man program, and if it fails to find a manual page, then it check the help command for info, and pipes the output to “less” which makes it act more like man.

Of course you could always use help if man doesn’t return anything, but this is a helpful shortcut that will keep you from having to re-run commands.


The Cheapest NBN 50 Plans

Here are the cheapest plans available for Australia’s most popular NBN speed tier.

At Lifehacker, we independently select and write about stuff we love and think you'll like too. We have affiliate and advertising partnerships, which means we may collect a share of sales or other compensation from the links on this page. BTW – prices are accurate and items in stock at the time of posting.

Comments


Leave a Reply