31

I often see things like

read man xyz
For more information read xyz's man page.
see info xyz

so I wonder:

  • How can I get help on terminal commands generally?
  • What exactly are these man and info pages?
  • How can I find and view them?
41

What is a man page?

A man page (short for manual page) is the traditional form of software documentation on a Unix-like OS like Ubuntu. For the vast majority of commands and programs there's a man page which lists its options and explains its usage.

How can I find and view man pages?

Offline in a terminal

Man pages are automatically installed on your system together with the commands they describe. To view and search man pages there's the command man:

man mv

displays the man page of mv while

man -k mv

searches names and short descriptions of all installed man pages for the string mv. POSIX Extended Regular Expressions are allowed and it's a search, so this will also find e.g. git-mv and semver, if you want to search exactly mv use ^mv$ instead.

See What is the difference between `man` and `man (#)`? to read about man page sections. For more information read man's man page. ;)

How can I influence how a man page is displayed?

The default program to display man pages is less. This so-called pager provides a helpful search function, just enter / followed by the search term, e.g.

/--version

and press Enter. This will mark every finding and scroll to the first one. Press N to go to the next finding and ⇧ Shift+N to go to the previous one (see How can I search within a manpage?). For a list of commands press H, to exit less press Q.

Beside less there are other pagers available: pg, most and w3m just to list three. I recommend most: It comes with a very useful coloring of key words making a man page much easier to read and navigate, see for yourself:

most screenshot displaying mv's manpage

To view a man page in a different than your default pager use the -P option, e.g.:

man -P most mv

If you want to change the default pager manpages are displayed with you have two options:

  • change the default pager solely of man

    export MANPAGER=most
    

    To make the change persistent add this command to your ~/.bashrc file.

  • change the default pager of your whole system

    sudo update-alternatives --config pager
    

Fans can even (ab)use vim as the MANPAGER, see this article written by muru.

Man pages are displayed in the font specified in your terminal emulator settings. If you work with the terminal regularly you might want to change this font; I can only recommend Hack – a typeface designed for source code, see the screenshot above for its beauty.

Offline via GUI

A nice and easy way to display man pages with a simple GUI is the preinstalled yelp program. To start a man page with yelp execute yelp man:PROGRAM or gnome-help man:PROGRAM, e.g.:

yelp man:mv

You can also view man pages with your preferred browser, see How do I make man pages open in a web browser?, e.g. for man mv in firefox:

man -Hfirefox mv

Last but not least you can convert man pages to PDF and view them with your preferred PDF viewer, see: Is there a way to print info/man pages to PDF?

Online

http://manpages.ubuntu.com

You can view the man pages of programs available via the repositories of every currently supported Ubuntu version with the shorthand URL manpg.es/PROGRAM, e.g. http://manpg.es/mv. This opens mv's man page for the latest Ubuntu release, you can choose a different release in the top bar. To search for man pages you can use e.g. http://manpages.ubuntu.com/cgi-bin/search.py?q=mv.

As explained above man can only display man pages of software installed on the system. To view man pages from http://manpages.ubuntu.com using a terminal pager there's dman available in the bikeshed package.

Other sources

When you read documentation from other online sources it's a good idea to keep an eye on the program version. Most programs have a --version option that displays the version of the program in question, e.g.

$ mv --version
mv (GNU coreutils) 8.25

There are a lot of websites which dedicated themselves to make man pages easily available, I'm just going to present the two I like the most:

  • man7.org comes with useful syntax highlighting, but it features only the last released version of the program
  • manpag.es hosts man pages of Ubuntu releases long gone EOL

Source not already linked: https://wiki.ubuntuusers.de/man/

  • Another helpful trick (at least if you're a programmer) is to write a small script to dump man's output into your text editor of choice. E.g. (\n is newline) #!/bin/tcsh\n set name = $argv[$#argv]\n set file = /tmp/man.$name.out\n /usr/bin/man $* | col -bx > $file\n (path to your editor) $file\n rm $file\n A similar but editor-specific macro will allow you to call man from within the editor, which is quite helpful. – jamesqf Jan 4 '18 at 3:27
  • @jamesqf Interesting, why do you do and when do you use that? As editors are usually able to read from stdin you can simplify it to e.g. man $*|col -bx|nano - or man $*|col -bx|kate -i. – dessert Jan 4 '18 at 9:06
  • @jamesqf if you export man page to text file in order to search or navigate easily, you really should consider having a look at the "SUMMARY OF LESS COMMANDS" page.It can be opened by typing 'h' in less (man use less command for pagination so it works from man too) – Ludovic Ronsin Jan 4 '18 at 16:11
  • @Ludovic Ronsin: I do it in my editor rather than less for two reasons. First, because I know my editor's commands (which are far more powerful than the less commands), and don't have to bother learning yet another set of commands, which I would inevitably confuse in different contexts. Second, because I can hook the editor version to a keypress (Alt-m, as it happens) and thereby get help on any function call that has a man page. As for why I do it the way I do, I wrote it 20+ years ago, and it worked well enough. – jamesqf Jan 5 '18 at 3:45
  • @jamesqf would just setting PAGER="vim -" do? – d33tah Jan 5 '18 at 19:31
13

The basics have been covered already, but one website I think is quite helpful for telling you what a command does is https://explainshell.com, which breaks down a command into its sections and shows what each bit does.

enter image description here

  • 1
    +1 That's absolutely not what I was after when I wrote this Q&A, but it's a great resource I didn't know about – thank you very much! As the other answers deliberately cover one main topic, maybe you extend your answer to cover online tools in general? shellcheck.net comes to mind… – dessert Jan 4 '18 at 7:27
12

What is an info page?

Alongside

man program-name

there is often also

info program-name

Sometimes they are the same (duplicates), but sometimes one of these pages contains more information. For example

info ddrescue

contains more information than

man ddrescue

and

info date

contains more information than

man date

The balance between man and info depends on the policy of the people who maintain the particular program [package].

See this link for more details,

unix.stackexchange.com/questions/19451/difference-between-help-info-and-man-command

10

What is the help command?

help displays helpful information about bash built-in commands. It provides help for bash shell commands only. You can use type to determine whether a command is such a built-in, e.g. type echo vs. type rm.

It is called with a pattern as an argument:

help if

displays the help page for the if command. If you're just interested in the syntax of a command use the -s option, if you want help to produce output in man page format use -m. To view long help texts conveniently you can pipe the output to your preferred pager (see this answer's “How can I influence” section):

help -m if | less

Comparison with man and info

You can run and compare the following commands:

help echo  # for the bash built-in command `echo`
man echo   # for the program `/bin/echo`
info echo  # for the program `/bin/echo`

Like in this example there are programs who are available both as a built-in and a usual program (see Why is there a /bin/echo and why would I want to use it?), in this case the man page usually contains a note indicating that.

See this link for more details: Difference between help, info and man command · U&L

a program's option -h and/or --help

Usually there is built-in help in the programs themselves available via at least one of the options -h, --help or -?:

PROGRAM -h
PROGRAM --help
PROGRAM -?

If both options -h and --help exist, they are often equivalent, but sometimes you get 'more help' with --help, -H, --longhelp, --help-all or similar commands. This behaviour is documented in the program's man/info page.

Usually there is more information via man and info, but sometimes there is exclusive information via -h. Run and compare the output of

man lsblk

and

lsblk -h

Some programs like df, tar and rsync use the option -h for something else. This is described in the man/info page of each program.

Again you can pipe the output to your preferred pager, e.g.:

lsblk -h | less
  • Thanks for mentioning --help, that is often the only thing I need with most commands, and always the first thing I try. – JPhi1618 Jan 4 '18 at 21:01
6

What is a tutorial and how can I find a useful one

When you have some experience of linux, the man pages, info pages and help options are very useful. But in the beginning, they can be difficult to understand; you need more detailed help to get started.

You can find detailed help in tutorials,

  • detailed explanation how to use a command
  • examples

Usually you will find tutorials via the internet, sometimes there is a useful tutorial in the man page or info page.

  • Try some search strings when you use your web browser's search engine, for example

    • Looking for specified tools

      • nano tutorial
      • sed tutorial
      • imagemagick tutorial
      • rsync tutorial
    • Looking for tasks (and finding tutorials for various tools)

      • linux text mode editor tutorial
      • linux batch mode picture editor tutorial

Look briefly at a few of the links that you find, and start working with a tutorial that fits what you need.

  • man rsync is detailed enough for me to use as a tutorial, but you might want more details (and look for a tutorial via the internet).
  • info ddrescue has a good built-in tutorial.
  • Perfect, thank you for your constant contribution – I feel this question will grow a very useful source we can beginners point to. I'll add an index of contents to the question and link the answers to spare viewers the scrolling. – dessert Jan 5 '18 at 10:33
  • 1
    @dessert, This is a good initiative by you, and I'm glad to contribute :-) – sudodus Jan 5 '18 at 11:02
3

tldroid: An Android app which gives quick info about a Linux/unix/mac command

https://play.google.com/store/apps/details?id=io.github.hidroh.tldroid

2

My favorite is commandlinefu.com, have a function in your .bashrc or .zshrc like this

cmd() { curl "http://www.commandlinefu.com/commands/matching/$(echo "$@" \
    | sed 's/ /-/g')/$(echo -n $@ | base64)/plaintext" ;}

Let's try cmd mount cd, I called my function cmd, you can call it whatever you want

enter image description here

The function above searches commandlinefu's website, it's a community driven website much like here, users have the ability to upvote commands and so on. Then it shows the top results as in the picture.

or there's a new way to do that by using this.

http://samirahmed.github.io/fu/

Here's a tutorial.

Let's do fu cron

enter image description here

1

Figure out how to open a terminal window and issue the command man man. Type the space bar to advance to the next screen whenever it says "More" at the bottom. You are reading the manual page for the manual-reading program, man!

There is a very small chicken-and-egg problem for you to get through. The man command helps you read the manual about every command on the system. But the man output uses another command called more. You can also read man more to learn additional navigation commands for more.

And that is everything! I learned everything I know about unix by reading the man pages for hundreds of commands.

  • 3
    On Ubuntu, man uses less by default, not more. – muru Jan 5 '18 at 16:21
0

Many have mentioned man already. A little cool feature for man few are aware of is

man -t $(manpage) > manpage.ps

which produces a PostScript file for the manual page. PostScript can be easily converted to PDF. This results in a much nicer formatting than the default command line terminal version of man.

For example:

man -t man > man.ps

pstopdf man.ps

I've just tested it on Ubuntu (and it should work on other Linuces) and Mac OS.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.