How can I get help on terminal commands?

12,097

Solution 1

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/

Solution 2

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

Solution 3

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

Solution 4

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

Solution 5

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.
Share:
12,097
dessert
Author by

dessert

For my pronouns see here: http://my.pronoun.is/nobody/nobody/nobody%E2%80%99s/nobody%E2%80%99s/noself This page intentionally crammed with flair™.

Updated on September 18, 2022

Comments

  • dessert
    dessert almost 2 years

    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?
  • jamesqf
    jamesqf over 6 years
    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.
  • dessert
    dessert over 6 years
    +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
    dessert over 6 years
    @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.
  • Ludovic Ronsin
    Ludovic Ronsin over 6 years
    @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)
  • JPhi1618
    JPhi1618 over 6 years
    Thanks for mentioning --help, that is often the only thing I need with most commands, and always the first thing I try.
  • jamesqf
    jamesqf over 6 years
    @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.
  • dessert
    dessert over 6 years
    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.
  • sudodus
    sudodus over 6 years
    @dessert, This is a good initiative by you, and I'm glad to contribute :-)
  • muru
    muru over 6 years
    On Ubuntu, man uses less by default, not more.
  • d33tah
    d33tah over 6 years
    @jamesqf would just setting PAGER="vim -" do?
  • jamesqf
    jamesqf over 6 years
    @d33tah: Might if I used vim regularly. Might even work with my editor, from the command line. But my main motivation was to be able to access man from within an editor session. As usual with *nix, there are many ways to achieve a goal acceptably well. What's important is knowing that something is possible, e.g. that you aren't limited to the system default man output.