Unix: Getting information

Manual pages

Unix has for ages had an embedded help system known as manual pages. There exists a manual page for every command mentioned in this ebook. The manual page for a particular command consists of a one line description of the command (also used by whatis and apropos), a synopsis (summary) of all the variant uses of the command, a brief description, and a list of all the options the command can take, and how each option modifies the behaviour of the command. To read the manual page for a particular command, type man command.

For instance, to find out more about the options you may use with the wc (word count) command, type:

$ man wc

Alternatively:

$ whatis wc

gives a short one-line description of the command, but omits any information about options etc.

When you are not sure of the exact name of a command, try:

$ apropos keyword

This command will give you a list of commands with the keyword in their manual page's short description. For example, try typing:

$ apropos copy

Exercise

Use the manual pages to find information about the man command. What options should you use to make the man command produse the same outout as whatis and apropos?

Gnu information system

In addition to the manual pages, there is a newer embedded help system known as info. It is part of the Gnu project from the Free Software Foundation.

The gnu information system usually provides more information and better information than manual pages if you're using a variant of Gnu/Linux and FreeBSD. Unlike the manual pages, which displays all information on a topic as a single, long page, the information system is hierarchical, and lets the reader drill down on a subject by selecting sub-topics from a menu.

Now try it out. For example, look at the info page about grep:

$ info grep

To quit info, type the single letter q.

Unfortunately, the the commands used by info to navigate is unlike any other Unix application. Below is a cheat sheet listing the essential command keys used by the Gnu information system:

Command Meaning
h show help about using info
x close help window (some systems)
[Ctrl]-X 0 close help window (some systems)
d go to directory (top of all topics)
t go to top node of current topic
[enter] go to menu item near cursor (marked with a *)
m go to named menu item
p go to previous topic
n go to next topic
u go up (to topic above present)
[space] page forward
[delete] page backward
q quit

In the Gnu information system, menu items (shown with a * character in the left marigin) links topics (nodes) together. To select a menu item, use the arrow keys to position the cursor near an menu item, and press [Enter].

Menu item can also be selected by naming them expliclitly. To try this out, do the following:

 $ info info-stnd

Then type m to go to a named menu item. Pay attention to the area at the bottom of the screen. This is known as the echo area. The text “Menu item:” should now appear in the echo area. You can now start typing in the name of the menu item you're interested in. Type “node ” (notice the [space] at the end). When you hit [space], the text in the echo area will auto-complete and spell out “Node Commands”. This is indeed the name of the menu item we're interested in. Your terminal should now look like the screen dump below.

info-stnd

Now hit [Enter] to go to the Node Commands topic and learn all about the keys to navigate between nodes.

The [space] and [Delete] keys lets you page forwards and backwards. They work both within nodes and between nodes. To read all about a topic, start at the top and use [space] to page through it until you reach the end.

Exercise

Use the information system to find information about using the info command. Find out how to search the information system for specific keywords. Hint: The menu item for searching is named “Searching Commands”.

What type of command?

In some situations, you may want to find out what type of command is executed when you type in a particular command string. Many of the standard program that is part of the Unix operating system comes in many different types. They share main characteristics, but there are subtle differences between the typess. How can you know what type you'll be using if you invoke the command?

The answer is the to use type command. This special command will tell you how command would be interpreted if it is used as a command name.

Examples, followed by a brief explanation:

$ type type
type is a shell builtin

The type command is one of the commands that are part of the shell.

$ type man
man is hashed (/usr/bin/man)

The man command is an executable with absolute path /usr/bin/man. The location of the executable is also hashed by the shell. That a command is hashed means that the shell, to speed things up, has remembered where to find it. (If you need, you can get make the shell forget with the command hash -r.)

$ type ls
ls is aliased to `ls $LS_OPTIONS'

The ls command is an alias which will invoke some non-aliased ls with the shell variable LS_OPTIONS as its first argument.

(Don't worry about not knowing what a “shell variable” is. They will be described later.)

$ type -a ls
ls is aliased to `ls $LS_OPTIONS'
ls is /local/gnu/bin/ls
ls is /usr/bin/ls

Invoking the type command with the option -a show all alternatives that exist for the ls command. The shell will invoke /local/gnu/bin/ls $LS_OPTIONS (followed by any arguments you specify on the command line.

System information

The following command will tell you how much memory is available:

$ cat /proc/meminfo
MemTotal:		1922436 kB	
…
SwapTotal:		4194296 kB
SwapFree:		4194296 kB
…

A lot of fields will be listed, but the two most interesting are the four fields show:

MemTotal
Total usable ram (i.e. physical ram minus a few reserved bits and the kernel binary code.)
SwapTotal
Total amount of physical swap memory.
SwapFree
Total amount of swap memory free.

Summary

Command Meaning
man command show the manual page for command
whatis command show a brief one line description of command
apropos keyword search for commands with keyword in their short description
type command show how command will be interpreted
type -a command show all alternatives that exist for command
hash -r remove command hashes