I often see things like
read
man xyz
For more information read xyz's man page.
seeinfo 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?
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.
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. ;)
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:
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.
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?
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.
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:
Source not already linked: https://wiki.ubuntuusers.de/man/
man $*|col -bx|nano -
or man $*|col -bx|kate -i
.
less
(man
use less
command for pagination so it works from man
too)
Commented
Jan 4, 2018 at 16:11
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.
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
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
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
-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
--help
, that is often the only thing I need with most commands, and always the first thing I try.
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,
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
Looking for tasks (and finding tutorials for various tools)
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.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
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
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/
Let's do fu cron
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.
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.
tldr
? You could also mentioncheat
and maybe cheat.sh.