Harley Hahn's Guide to
|
A Personal Note
Chapters...
Command
INSTRUCTOR |
Chapter 9...
Documentation:
Within the world of Unix, there are many different documentation systems, each with its own characteristics. Some are used widely; some serve a particular niche. In general, all such systems have two common goals: to make it easy for programmers to document their work, and to make it easy for users to learn how to use the tools created by the programmers. In this chapter, I am going to teach you how to use the two most important Unix documentation systems: the online Unix manual, a facility that comes with every Unix system; and Info, the official documentation system of the GNU project. Both of these tools are designed to be used with the Unix CLI (command line interface). The reason is that graphical programs are self-documenting, in the sense that they almost always have their own built-in help facility. Thus, when you want help with a GUI-based program, you don't use the online manual or Info. You look within the program itself, usually by pulling down a Help menu.
As we discussed in Chapter 2, Unix was developed in the early 1970s in New Jersey, at Bell Labs (then a part of AT&T). Soon after Unix was created, it became popular with programmers and researchers, first within Bell Labs and later in the computer science departments at a handful of research universities. As Unix grew in popularity, more and more people needed to learn how to use the system. However, the Bell Labs programmers were busy people who did not have the time, nor the inclination, to teach new users how to use Unix. Moreover, the prevailing culture encouraged anyone to create new tools and share them with other users. Thus, from one month to the next, the amount of material that one might need to learn increased, as did the number of new users. In response to these needs, the Unix developers adopted a two-part solution. First, they created an online manual, built into Unix itself, which contained information regarding every Unix tool. Since the Unix manual was itself part of Unix, it was available to all users all the time. This meant, for example, when a user at a far-away location had a question in the middle of the night, he or she would be able to turn to the manual for help. The second part of the solution was to encourage a work environment in which all Unix users both new and experienced were expected to try to answer their own questions before they asked for help. To be precise, what we might call the Unix tradition requires you to teach yourself and try to solve your own problems. However, if you have tried your best and you still have a problem, other Unix people will be glad to help you. The converse of this is that, once you are experienced, you are expected to help others. This Unix tradition was important for two reasons. First, it provided an efficient way for Unix to spread. Since people would only ask for help if they really needed it, experienced people were not called upon to waste their time helping others unnecessarily. Second, by making people responsible for teaching themselves, the Unix developers encouraged the type of independent thinking and personal creation that caused Unix to flourish. In fact, the Unix tradition bred a generation of users who were smart, independent, and willing to help others (when necessary), all working within an atmosphere of cooperative creativity. For example, if a programmer wanted a new tool, he was encouraged to create it for himself. Once the program was finished, it would be added to the general Unix system. The programmer would then write the relevant documentation, which would be added to the online manual. The new tool would be announced to the general Unix community, with the understanding that anyone who wanted to learn how to use it would read the online manual, experiment, and teach himself. If a user found a bug or had a serious problem, he or she was free to contact the author of the program. Thus, you can see the Unix tradition is based on two main ideas: Try your best to teach yourself before you ask for help; when others ask you for help, give willingly of your time. These ideas proved to be so important that they become embodied in a single, very odd word: RTFM. What's in a Name? Online In the old days, the word ONLINE was used to describe the idea of being connected to a specific computer system. For example, when you were logged into a system, we would say you were online. When we talk about the online Unix manual, we are using the word in this way. The manual is "online" because it is available to all the users of a particular Unix system. Today, we also use the term "online" to indicate that a resource or a person is connected to the Internet, not to a specific computer system. For example, once you are connected to the Net, you can use online banking, online bill paying, and even participate in an online relationship. Thus, as a Unix user, you are online in two different ways: you are logged into a particular Unix system, and you are connected to the Internet.
The word RTFM is unique in several ways. First, it is the longest verb in the English language without vowels. Second, it is usually spelled with all uppercase letters. Finally, because RTFM has no vowels, the word is pronounced as four distinct letters ("R-T-F-M"), even though it is not an acronym. As I mentioned, RTFM is a verb. (I'll explain its origin in a moment.) We use it to embody the idea that, before you ask for help or information, you must try to solve the problem or find the information for yourself. The word RTFM can be used in two ways. First, First, you can tell someone not to bother you for help until he has tried to help himself. For example, if someone says to you, "Can you show me how to use the whatis command?" you might reply, "RTFM." In this case, RTFM means, "Don't ask for help until you have checked with the online Unix manual." Second, you can also use RTFM to indicate you have tried to solve a problem on your own before asking for help. For example, you might email a message to a friend: "Can you help me get my Linux system to share files with a Windows PC? I have RTFM'd for two days now, and I still can't get it to work without having to reboot Windows every few hours." Since the early days, the idea of RTFM has been an integral part of the Unix culture. Today, its use is also widespread on the Internet, especially within Usenet and the open source community. (See Chapter 2 for a discussion of the open source movement.) As the use of RTFM has expanded, so has its meaning. Today, the doctrine of RTFM requires you to look for information not only in the online Unix manual but on the Internet as well. Thus, it is a good idea not to ask for help until you have at least used a search engine, such as Google, to look for relevant Web sites. With respect to Usenet, if you are a newcomer to a discussion group, it is expected that you will read the FAQ (frequently asked question list) for that group before you send in your first posting. This too is considered RTFMing. hint When you are looking for solutions to Unix problems, don't forget Usenet, the worldwide system of discussion groups. The easiest way to search Usenet is to use the Google Usenet archive, called Google Groups. I have often found answers to even the most obscure questions by searching the Usenet archive. If after all your searching, you can't find what you want, you can post a request in the appropriate discussion group. If you do, be sure to mention that you have already RTFM'd. What's in a Name? RTFM, RTFM'd RTFM is a verb, indicating the idea that, when you need information or you are working on a problem, you should spend some time trying to find what you need on your own before you ask someone else for help. When we talk about already having performed such actions, we use the past participle of the verb, which is spelled RTFM'd, not RTFMed. Thus, you might say, "I have RTFM'd for the last two hours, and I can't figure out how to connect my cat to the Internet." Like many technical words, RTFM started life as an acronym. In the early days of Unix, RTFM stood for "Read the fucking manual,"(*) referring, of course, to the online Unix manual. Today, however, RTFM is not an acronym, but a legitimate word in its own right. This is not unusual. The same can be said for many other technical words, such as radar ("radio detection and ranging"), laser ("light amplification by stimulated emission of radiation"), and scuba ("self-contained underwater breathing apparatus"); as well as various proper nouns, such as Nato ("North Atlantic Treaty Organization"), and collective nouns, such as yuppie ("young urban professional"). The biggest difference between RTFM and other such words is that RTFM is normally spelled with uppercase letters. This only makes sense as RTFM is much more important to our culture than radar, laser, scuba, Nato or yuppies. * Footnote Sometimes you will see RTFM explained by using the euphemism "Read the fine manual". However, as you know, it is my practice within this book to explain things as they really are. In this case, as you can see, the original meaning of RTFM used profanity, and I think you should know the truth. Thanks for not being offended.
The UNIX MANUAL, often referred to as the ONLINE MANUAL or, more simply, the MANUAL, is a collection of files, each of which contains documentation about one specific Unix command or topic. The manual is available on every Unix system, where it is accessible to any user at any time. To use the manual, you enter a simple command (which we will discuss in a moment). The information you requested is then presented to you, one screenful at a time. In the olden days (of mainframe computers), most computer systems came with a large amount of highly technical, printed documentation, which was kept in a central location, such as a computer room or a terminal room. Not only was the documentation awkward to use, it was often out of date, and it was common to have to deal with a stack of printed updates. For this reason, the old-time computer manuals were stored in large, unwieldy holders that could be opened to insert new pages, but were generally awkward to use or to move from one place to another. Unix was different. From the beginning, the documentation was always online, which meant that it was convenient for any user to read whatever he needed, whenever he wanted, on his own terminal. Moreover, because the online manual was stored as a collection of disk files, it was a simple matter to add new material by adding a new file, or update existing material by modifying a file. In the very early days,Unix systems did have a printed manual as well as the online manual. However, the information in the printed manual was the same as what was already available online. Accessing the Unix manual is easy. All you need to do is type the word man, followed by the name of the command you want to know about. Unix will display the documentation for that command. For example, to display the documentation about the cp (copy a file) command, enter: man cp Suppose you want to learn about the man command itself. Just enter: man man hint The man command is the single most important Unix command, because you can use it to learn about any other command. If you want to learn about more than one command name, just enter all the names on the same line. For example: man cp mv rm Unix will display the documentation for each command in turn. These three commands, by the way, are used to copy, rename [move], and delete [remove] files. We will meet them more formally in Chapter 25. What's in a Name? The Manual Unix manuals have always been important. Indeed, at one time, when Unix was primarily a product of AT&T's Bell Labs, successive versions of Unix were named after the current edition of the manual: Unix Sixth Edition, Unix Seventh Edition, and so on. Although there are many Unix books and references, when a Unix person refers to "the manual", you can assume that he or she is talking about the one and only online Unix manual. For example, say you are reading an email message from your system administrator describing a new program he has just installed on the system. At the end of the message, he says, "For more information, check the manual." You can assume, without asking, that he wants you to use the man command to read the appropriate entry in the online manual. To a Unix user, there is never any doubt as to which manual is The Manual.
In the very early days, Unix users used slow terminals that printed output on paper. Since there were no monitors, when someone wanted to learn about a command, he or she would have to print the relevant pages of the online manual. This wasn't as inconvenient as it might sound because, at the time, there weren't that many entries in the manual, and many of them were designed to fit on a single page. Today, the Unix manual has a large number of entries, many of which are much longer than a printed page. Still, it is the custom to refer to a single entry, no matter how long it is, as a PAGE or, more formally, as a MAN PAGE. For example, the documentation for Bash, the default Linux shell (which we will meet in Chapter 12), runs to well over 4,500 lines. Still, it is considered to be a single man page. Consider this example of word usage. You are in a Unix bar, quaffing down a glass of caffeinated chocolate milk, and you happen to overhear two programmers talking. The first one says, "I can't decide what to get my girlfriend for Valentine's Day. Do you have any ideas?" to which the other programmer replies, "Why not print her a copy of the Bash man page?"
Virtually all the entries in the online manual are longer than the number of lines on your screen. If an entry were displayed all at once, most of it would scroll off the screen so fast that you would not be able to read the text. This is a common situation for which Unix has a good solution: send the output to a program that displays the output more carefully, one screenful at a time. There are three such programs, called paging programs, that are commonly used on Unix systems. Their names are less, more and pg. The best — and most widely used — paging program is less, which we will talk about in detail in Chapter 21. For now, I will give you a brief overview, so you will know enough to be able to read the online manual. If you want to practice as you are reading, enter one of the following commands, each of which displays information about a particular shell: Bash, the Korn shell, or the C-Shell:
man bash
My suggestion is to display the man page for the shell that you plan on using or that most people use on your system. If you are not sure, just pick one it's only for practice. The job of a paging program is to display data one screenful at a time. After each screenful, the program pauses and displays a prompt at the bottom left-hand corner of the screen. The prompt differs depending on what paging program is being used. The less and pg programs display a colon: : On some systems, less displays a message instead of the colon. For example: byte 1357 In this case, less is telling you that it has just displayed character number 1357. (Each byte holds one character.) As you page through the file, this number will increase, giving you a rough idea of how far you are from the beginning. The more program displays a prompt that contains the word "More". For example, you might see: --More--(10%) This means that there is more to come and that you are 10 percent of the way through the page. Once you see the prompt, you can display the next screenful of information by pressing the <Space> bar. (With pg, you press <Return>.) When you are finished reading, press q (the letter "q") to quit. As you are reading a man page, there are many commands you can use. Normally, however, you won't need them. Most of the time, you will simply press <Space>, reading one screenful after another. When you reach the end of the page, or when you find what you want, you will press q to quit. From time to time, you may want to use some of the other commands, so I'm going to take a moment to describe the ones that I find most useful. These commands are summarized in Figure 9-1. As I mentioned, there are many others, more than you will ever need. Note: The commands in Figure 9-1 are for systems that use less. If your system uses more or pg, there will be some differences. If you have a problem, use the h command for help.
With any program, the most important command is the one that displays the help information. In this case, all you need to do is press h (the letter "h"). When you do, the man page information will be replaced by a summary of all the paging commands. When you are finished reading the help information, press q to quit and return to the man page. Note: The summary is quite long and, just as with the man page itself, you will have to press <Space> to work your way through the information. However, the most important commands will be near the top of the summary. The commands I am about to discuss are for the less paging program, because it is used with most Unix systems. If your man command uses either more or pg, all you have to do is press h, to get the help summary for that particular paging program. My suggestion is that, as you read, follow along at your computer, trying the various commands. To start, if you are looking for a specific pattern, press the / (slash) character, type the pattern, and then press <Return>. For example: /output<Return> This example tells the paging program to skip forward to the next line that contains the word "output". Once you have specified a pattern, you can search for it again by entering the / character by itself: /<Return> If you search for a pattern, but it's not the line you want, you can keep searching for the same pattern, over and over, until you find what you do want. Just keep pressing /<Return>(*). * Footnote This feature is taken from the vi editor, which we will meet in Chapter 22. Alternatively, you can press n (next) to search for the same pattern, either once or more than once. To search backward, use ? instead of /. For example: ?output<Return> To search backward for the same pattern, use ? by itself: ?<Return> Alternatively, you can press N to search backward for the same pattern. To move down one screenful, as you already know, you press <Space>. You can also press f (for forward). To move up one screenful, press b (for backward). Alternatively, you can move down and up by pressing <PageDown> and <PageUp>. To move down one line at a time, press the <Return> key or the <Down> key (that is, the down-arrow key). To move up one line at a time, press the <Up> key (that is, the up-arrow key). To jump to the top of the page, press g ("go to top"). To jump to the bottom of the page, press G ("go to bottom").
The way in which you read man pages so far as we have discussed it is conceptually simple. You use the man command to display information about a particular topic. You then look at the information, one screenful at a time, until you find what you want. This is the common way to read man pages using the standard Unix CLI (command line interface). However, if you put the man command together with the Unix working environment, you can access man pages in a more sophisticated way. As we discussed in Chapter 6, you can use the CLI in two ways, with a terminal window or with a virtual console. My suggestion is to learn how to use two terminal windows at the same time, one for doing your work and the other for displaying man pages. For example, let's say you are working within one terminal window, editing a file with the vi text editor (see Chapter 22). You need some help, so you decide to look at the vi man page. If you do so by displaying the page in a second terminal window, you can look at both the man page and the original window at the same time. You can see this in Figure 9-2. |
|
Figure 9-6: Sample page from the Unix manual MAN(1) USER COMMANDS MAN(1) NAME man - display reference manual pages; find reference pages by keyword SYNOPSIS man [-] [section] title ... man -k keyword ... man -f filename ... DESCRIPTION Man is a program which gives information from the programmer's manual. It can be asked for one-line descriptions of commands specified by name, or for all commands whose description contains any of a set of keywords. It can also provide on-line access to the sections of the printed manual. When given the option -k and a set of keywords, man prints out a one-line synopsis of each manual section whose listing in the table of contents contains one of those keywords. When given the option -f and a list of names, man attempts to locate manual sections related to those files, printing out the table of contents lines for those sections. When neither -k or -f is specified, man formats a specified set of manual pages. If a section specifier is given man looks in that section of the manual for the given titles. Section is either an Arabic section number (3 for instance), or one of the words "new", "local", "old" or "public". A section number may be followed by a single letter classifier (for instance, 1g, indicating a graphics program in section 1). If section is omitted, man searches all sections of the manual, giving preference to commands over subroutines in system libraries, and printing the first section it finds, if any. If the standard output is a teletype, or if the flag - is given, man pipes its output through more(1) with the option -s to crush out useless blank lines and to stop after each page on the screen. Hit a space to continue, a control-D to scroll 11 more lines when the output stops. FILES /usr/man standard manual area /usr/man/man?/* directories containing source for manuals /usr/man/cat?/* directories containing preformatted pages /usr/man/whatis keyword database SEE ALSO apropos(1), more(1), whatis(1), whereis(1), catman(8) BUGS The manual is supposed to be reproducible either on a photo-typesetter or on an ASCII terminal. However, on a terminal some information (indicated by font changes, for instance) is necessarily lost. |
To begin our discussion, let's take a quick tour of each of the basic headings. As I mentioned, you may see other headings from time to time, but once you get a bit of experience you won't have any trouble understanding the variations. Name: This is a one-line summary of the command or feature. Be aware that some summaries are vague; if you are confused, you may have to do a bit more RTFMing. Synopsis: This section shows the syntax of the command. This is the official explanation of how to enter the command. I describe command syntax in detail in Chapter 10, so we'll leave most of the discussion till then. For now, I just want to draw your attention to one point. In general, when you enter a command, you type a name, followed by options, followed by parameters. We'll discuss the technical details in Chapter 10, so don't worry about them for now. All I want you to understand is that you will see two variations of how the Synopsis section shows the options. First, you may simply see the word OPTION. In this case, the actual options are listed and explained in the Description section below. Here is an example, taken from the Linux man page for the ls command: ls [OPTION]... [FILE]... This convention is used with the man pages that come with the GNU utilities (see Chapter 2). Since the GNU utilities are used with virtually all Linux systems, this is what you will see on many of the Linux man pages. Here are two more examples. The first is taken from the FreeBSD manual; the second is from the Solaris manual.
ls [-ABCFGHLPRTWabcdfghiklmnopqrstuwx1] [file...]
In this case, the actual options are specified. (This is also the case with the sample man page you see in Figure 9-6.) As with the example above, the details are explained in the Description section. The job of the Synopsis is to provide a quick summary of the command. Description: This section is the largest one and usually takes up the bulk of the man page. Its purpose is to explain most of the details you need to know, including how to use the options. On some systems, the full explanation is divided into two separate sections: Description and Options. As you read, it helps to remember that you are looking at a reference manual, not a teaching guide. Be prepared to find that many descriptions are difficult to understand until you know what you are doing. This is normal. If you have trouble, keep reading until you run out of patience: some of what you read will stick. When you learn more, you can try again. Realize also that there are some descriptions (such as those for the various shells) that you will probably never understand completely. If this bothers you, remind yourself that the people who do understand everything in the Unix manual are much less attractive and socially adept than you. Files: This section shows the names of the files that are used by this command. If the information in this section makes no sense to you, you can ignore it. (We will discuss file names in detail in Chapter 23.) See also: This is an important section. It shows you other places to look in the manual for more information. In particular, you will see commands that are related in some way to the command under discussion. Following up these references is a good way to learn. Concentrate on the references to the Section 1 man pages. Environment: Before I can explain this section, I need to lay a bit of groundwork with respect to the idea of variables. A variable is an entity with a name and a value. Within Unix, there are certain variables whose values are available to all programs and shell scripts. (A shell script is a file containing a list of commands that can be executed automatically.) Such variables are known by several different names depending on the context: environment variables, global variables, or shell variables (see Chapter 12). By convention, environment variables and global variables are given names consisting of all uppercase letters. This section of the man page describes the environment variables that are used by the program. For example, the man page for the date command refers to an environment variable named TZ, which shows what time zone should be used. Author: The name of the person or persons who worked on the program. You will often see this section when you are looking at a man page for one of the GNU utilities. This is because the Free Software Foundation, which runs the GNU Project (see Chapter 2), likes to give credit to programmers. Diagnostics: This section can contain two types of information. First, there may be an explanation of possible error messages. Second, there may be a list of error codes that a command can return upon completion. Error codes are important for programmers who want to call upon a command from a program or shell script and then test to see if the command completed successfully. If the command was successful, the error code will have the value 0 (zero). Otherwise, the error code will be non-zero. Bugs: All programs have two kinds of bugs: the ones you know about and the ones you don't know about. The original developers of Unix recognized that no program is perfect and users deserve to know about the imperfections, Thus, many man pages contain a section devoted to documenting known problems. Some commercial Unix vendors have decided that a section named Bugs gives the paying customers the wrong idea. Thus, you may see this section living under an assumed name, such as Notes or Limitations. Don't be fooled, bugs are bugs and, if you use the program, you have a right to know about them.
When you enter the man command, Unix displays the entire manual page. Sometimes, however, you only want a quick description. In such cases, you have an alternative. As I explained above, the Name section of a man page contains a one-line description. If all you want to see is this single line, type man -f, followed by the names of one or more commands. For example: man -f time date In this form of the man command, the -f is called an option. (We will discuss options in Chapter 10.) The letter f stands for the word "files". Each man page is stored in a separate file; when you use the -f option, you are telling man which files to look at. As a convenience, you can use the command whatis as a synonym for man -f. For example, if you want to display the time, but you are not sure whether to use time or date, enter either of these commands:
whatis time date
You will see something like this:
date (1) - print or set the system date and time
You can ignore the last two lines as they do not refer to Section 1 of the manual. Looking at the first two lines, you see that the command you want is date. The time command actually measures how long it takes for a program or command to execute. As you know, when you enter the man command, you can specify a particular section number (such as man 1 date). With man -f or whatis, you cannot be so specific. Unix will always search the entire manual. Thus, a good way to find out what your manual contains is to enter: whatis intro You will see quick summaries of each of the intro pages. (Try it.) Note: For the whatis command to work properly, the man pages must be preprocessed in a certain way. This involves collecting all the one-line descriptions and storing them in certain files. It is these files that whatis searches, not the actual manual (that would be far too slow). If the preprocessing has not been carried out, whatis will not return useful information. If this is the case on your system, talk to your system administrator.
When you want to learn about a specific command, you can use man to display the man page for that command. What if you know what you want to do, but you are not sure which command to use? The solution is to use man with the -k option. This searches for commands whose NAME sections contain specified keywords. (The letter k stands for "keyword".) For example, say you want to find all the entries in the manual that have something to do with the manual itself. Enter: man -k manual As a convenience, you can use the single word apropos as a synonym for man -k: apropos manual Note: When you pronounce apropos, the accent is on the last syllable, and the "s" is silent: a-pro-poe'. This is because the name comes from a French expression and, in French, an "s" at the end of the word is normally not pronounced(*). * Footnote French people are good at spelling, but bad at pronouncing. The apropos command searches through all the one-line command descriptions, looking for those that contain the same string of characters you specified. To make the command more powerful, Unix does not distinguish between upper- and lowercase. Here is some sample output from the previous example.
catman (8) - create the cat files for the manual
Notice that there are two commands of interest, man and whereis, as they are the only ones in Section 1. Notice also that the route command was cited because the characters "manual" happened to appear in its description. You might ask, why don't apropos and whatis appear in this list? After all, both commands help you access the online manual. To answer this question, enter: whatis apropos whatis You will see that the word "manual" does not appear in these descriptions:
apropos (1) - locate commands by keyword lookup
The lesson here is: The apropos command is not magic all it can do is search blindly for character strings so if you can't find what you want, try asking in a different way. hint Most commands are actually programs. For example, the man command is really a program named "man". However, some of the most basic commands, called builtin commands, are carried out by the shell itself. These commands will be documented within the man page for the shell. They will not have their own separate entries in the manual. If you are looking for a command that you know exists, but you cannot find it under its own name, check the man page for your shell:
man bash
If you are a Bash user, there is a special man page that will list all the builtin commands: man builtin What's in a Name? Apropos In Unix, the apropos command is a synonym for man -k. The word comes from the French expression à propos meaning "related to". In English, "apropos" is a preposition meaning "concerning" or "with reference to". For example, you might read the following passage in a novel: "...Amber raised her eyebrows and reached over to touch the tall, handsome programmer lightly on the lips. As she shook her long blond hair, she felt a frisson of desire travel through her lean, lissome body. 'Apropos to your proposal,' she cooed seductively, batting her eyelashes, 'I'd love to be the Mistress of Ceremonies at your Unix bachelor party. But does Christine know about the invitation?'..."
There are two marvelous words you will see from time to time: FOO and BAR. These words are used as generic identifiers by programmers. You will see them, not only throughout the world of Unix and Linux, but on the Web and in Usenet discussion groups. The idea is that whenever you want to refer to something without a name, you can call it "foo"; when you want to refer to two things without a name, you call them "foo" and "bar". Nobody knows for sure how this tradition got started, but it is used a lot. For example, here is an excerpt from the Linux man page for the exec command. (Don't worry about the meaning.) "...Most historical implementations were not conformant in that foo=bar exec cmd did not pass foo to cmd..." From time to time, you will also see the word FOOBAR used in the same way. For example, the following is a question written by a well-known Unix professor for one of his final exams. (Again, don't worry about the meaning.) "...Give a Unix command, and the equivalents in sed and awk to achieve the following: Print the file named foobar to standard output, but only lines numbered 4 through 20 inclusive. Print all the lines in file foobar, but only columns numbered 10 through 25 inclusive..." What's in a Name? Foo, Bar, Foobar In the world of Unix and on the Internet, the words foo, bar and foobar are commonly used as generic terms to represent unnamed items within a discussion or exposition. Where do these strange words come from? The word "foobar" derives from the acronym FUBAR, which was popular during World War II. FUBAR means "fouled up beyond all recognition"(*). The word "foo", seems to have a more robust history. No doubt foo owes much of its popularity to foobar. Nevertheless, foo seems to have been used on its own even earlier. For example, in a 1938 cartoon, Daffy Duck holds up a sign that reads "Silence is Foo" (which is absolutely correct). Some authorities speculate that foo might have roots in the Yiddish "feh" and the English "phoo". * Footnote Actually, the F in fubar doesn't really stand for "fouled". However, I thought it might be offensive to use the word "fuck" twice in the same chapter (see the discussion on RTFM). I'm sure you understand.
Info is an online help system, separate from the Unix manual, which is used to document the GNU utilities (explained in Chapter 2). Since many types of Unix including virtually all Linux systems use the GNU utilities, most people find it useful to understand how to use both the online manual and Info. Indeed, you will find that many of the Linux man pages refer you to Info for more information. Superficially, Info is a bit like the online manual. Information is stored in files, one topic per file, just like man pages. The files are called Info FILES and, to read them, you use the info program. Just type info followed by the name of a command. Consider the following two examples. The first displays the man page for the date command. The second display the Info file for the same command:
man date
Like the online manual, info will show you information one screenful at a time. As is the case with the manual, you press <Space> to move from one screenful to the next, and you press q to quit. However, as you will see in a moment, that is where the similarity ends. If you have trouble starting Info, you can check to see if it is on your system by looking for the info program. Any of the following commands will do the job (see Chapter 7):
which info
Alternatively, you can look for an info man page: man info If your system does not have the info program or an info man page, you can assume that you don't have Info (which means you can skip the rest of this chapter secure in the knowledge that your life is not passing you by). As you know, all Unix and Linux commands have a man page. However, many commands do not have an Info file. For this reason, if you try to display the Info file for a command that doesn't have one, Info will simply show you the man page instead. For example, the man command does not have an Info file. See what happens when you enter: info man There are three main differences between Info and the online manual. First, Info files contain not just information, but links to other Info files. Thus, reading an Info page is similar to reading a Web page in the sense that you can use a link to jump to another file.(*) This is not the case with man pages. * Footnote Unlike Web pages, Info files contain only plain text with very little formatting and no pictures. Thus, as you use Info, you can see what it was like to use the Web in its early days, when it was a primitive, text-based system. Second, as you are looking at an Info file, there are a lot of commands you can use, many more than are available with the online manual. This makes for a much more powerful environment. For this reason, some people prefer to look at man pages using info instead of man. Finally, as I described at the beginning of the chapter, the online manual was designed by the original Unix programmers at Bell Labs. Their goal was to keep things simple, both for the programmers who would create documentation and for the users who read it. Info was created by the people who developed the Emacs text editor. The chief architect was Richard Stallman, the founder of the Free Software Foundation and the GNU Project (see Chapter 2). Stallman trained at the MIT Artificial Intelligence Lab in the early 1970s, where there was a much different environment than Bell Labs. One of the most important differences was that MIT tended to build large, complex powerful systems, while the Unix programmers (who had a much smaller budget) valued simplicity. Compare, for example, Multics vs. Unix (see Chapter 1). Although Stallman was not your typical MIT programmer, he did tend to write programs that were very powerful, idiosyncratic, and had a great many esoteric commands. To a large extent, you can see these characteristics within both Emacs and Info. So, as you read the rest of this chapter and as you practice with Info, remember that it was brought to you by the same people who created Emacs. If you feel a bit confused, take solace in the fact that everyone else did the first time they tried to use Info. As complex as Info is, it is actually part of something larger called TEXINFO, the official documentation system for the GNU project. Texinfo is a sophisticated set of tools that allows you to use a single information file to generate output in a variety of formats: Info format, plain text, HTML, DVI, PDF, XML and Docbook. For our purposes, all we need to know is that GNU documentation starts life as Texinfo files, which are then used to generate Info files. For this reason, you will sometimes see Info referred to as Texinfo. For example, if you ask someone a question and he asks, "Have you checked with Texinfo?" he is telling you to use Info. Since Info is so complex, we can't cover everything, nor would we want to. Instead, I will confine myself to three main goals, showing you: how to use Info to display what you want, how to maneuver around the Info system, and how to display the Info help information. Once you have these three skills, you can RTFM as necessary, and teach yourself whatever you need to know. What's in a Name? Texinfo When you first look at the name Texinfo, you might think that it should be Textinfo. After all, it is the name of a text-based information system. Actually, the spelling of Texinfo is correct: it comes from TeX, a typesetting system created by the eminent computer scientist Donald Knuth (pronounced "kuh-NOOTH"). The name TeX comes from the Greek word techni, from which we get the English word "technical". Techni refers to an art, a craft or, more generally, the end result of someone's effort. Thus, the letters TeX are not the English letters T-E-X; they are actually the Greek letters Tau, Epsilon and Chi, the first three letters of techni. If you want to be pedantically accurate, you should pronounce the Chi as the "ch" in the Scottish word "loch" or the name "Bach". Most computer people, however, pronounce the Chi as a "K". So how should you pronounce Texinfo? You have four choices. First, if you like being pedantically accurate you should say "Te[ch]info", where [ch] is the funny sound I described above. If you are a programmer and you want to look like an insider, say "Tekinfo". If you want to fit in with the non-technical crowd, say "Texinfo", which is what most people do who read the word literally. Finally, if you want to be a leader within your social circle, tell everyone that it is obvious the name should really be "Textinfo". Explain that the second "t" must have been left out accidentally, and it is about time someone fixed the mistake. (Actually, you might be correct: just because someone invents something, doesn't mean he has the right to give it a foolish name just to show how clever he is.)(*) * Footnote In my time, I have met both Donald Knuth, who named TeX, and Richard Stallman, who named GNU. If you put them in a room together, probably the only point they would agree on is that both TeX and GNU are good names.
You may remember that, in Chapter 8, we discussed the idea of data structures, a basic concept of computer science. A data structure is an entity used to store and retrieve data according to a set of precise rules. At the time, I mentioned that the most common types of data structures are lists, linked lists, associative arrays, hash tables, stacks, queues, deques (double-ended queues), as well as a variety of tree-based structures. In Chapter 8, we discussed stacks, so you could understand how the dc calculator handles reverse Polish notation. In this section, we are going to discuss trees, because that is the data structure Info uses to store and retrieve Info files. Once you understand trees, you can make sense out of the commands you use to control Info. If you don't understand what a tree is, you can certainly use Info, but it won't be fun and it won't be easy. When a computer scientist talks about a tree, he is referring to a family of complex data structures. So, to make life simple, let's start with a simple metaphor. Let's say you decide to go on a hike. You start at the trailhead and find there are several possible paths to follow. You choose one of them. You follow that path until you come to a fork, at which point you have a choice of several new paths. Again, you make a choice and keep walking until you come to another fork and are forced to make another choice. And so on. Once in a while, you follow a path that leads to a dead end. When this happens, you need to go back to a previous fork and make a different choice. In the language of computer science, we call each fork a NODE. The main node (the trailhead in our example) is called the ROOT. The path that joins one node to another is called a BRANCH. When a branch leads to a dead end, it is a special type of node we call a LEAF. Here is the technical definition: To a computer scientist, a TREE is a collection of nodes, leaves, and branches, organized in such a way that there is, at most, one branch between any two nodes.(*) * Footnote The ideas behind computer trees are taken from a part of mathematics called graph theory. Mathematical trees are similar to computer trees. However, the terminology is different. Within graph theory, a node is called a "vertex" (plural "vertices"), and a branch is called an "edge". Thus, if you ever meet a graph theorist, you can expect him to say things like, "Strictly speaking, the Info system uses a data structure that isn't a real tree. Since some vertices are joined by more than one edge, you should really describe it as a connected graph in which tree-like objects are embedded." (Now you see why Unix people tend to not invite graph theorists to parties.) Although all of this sounds a bit complicated, it is similar to what we see when we look at a real tree. As an example, look at the sample tree in Figure 9-7. Notice that, unlike a real tree, a computer tree is usually drawn with the root at the top.
Within computer science, there are a variety of different types of trees, each with its own characteristics. The type of tree I have just described is the data structure Info uses to store information. Each Info file is broken into parts and stored as a series of nodes. As you read a file, you move from one node to another. This allows you to read an entire file from beginning to end, one node at a time. As you are looking at a particular node, we say that you are VISITING that node. Many nodes also contain LINKS that allow you to jump to other, related files (just like links on a Web page). Using Info requires three basic skills. You need to understand how to:
We will now discuss each of these skills in turn.
To start the Info system, you use the info command. There are two variations. First, if you want to display information about a specific command, type info followed by the name of the command. For example:
info date
If you are not sure which command you want to learn about, or if you want to browse the system, enter the info command by itself: info When you start Info in this way, it displays a special node called the DIRECTORY NODE. The Directory Node contains a list of major topics, so you can consider it to be the main menu for the entire Info system.
Info has a fair amount of help information you can read to get started. Before you do, be sure to read to the end of this chapter. The place to begin your journey is the info man page. Either of the following commands will do the job:
info --help | less
Notice that, in the first command, there are two hyphens and no spaces before the word help. We will discuss what this means in Chapter 10. Once you have read the man page, you can display a short introductory Info file, by entering the command: info info Next, you should read the Info tutorial. To do so, start Info and press the h (help) key. It may be a bit confusing, but if you have read this chapter, you'll do okay. Once you have finished the tutorial, take a moment to display the Info command summary and skim the list of commands. You can display this summary by pressing the ? (question mark) key. hint At any time, from within any Info file, you can display the built-in tutorial (by pressing h) or the command summary (by pressing ?). As you read these files, don't worry about understanding everything. Just learn the basic commands, and add to your repertoire as the need arises. When it comes to Info, no one knows (or needs to know) everything. As you are using Info, you are always looking at a node. If you want to leave that node and return to the last node you were reading, press l (the letter "L"). For example, say you are reading the node that contains help for the date command. You press ? to display the command summary (a new node). To return to the date node, all you need to do is press l. Don't press q, or you will quit Info completely and end up back at the shell prompt. As you read the command summary, you will see <Ctrl> keys referred to using the notation C-x, instead of ^X or <Ctrl-X>. (This is an Emacs convention.) You will also see the notation M-x. The M- stands for Meta key, a very important concept in Emacs. For now, I'll just say that to use the Meta key, you can either hold down the <Alt> key while you press the second key; or press <Esc>, let it go, and then press the second key. For example, let's say you want to press M-x. You can use either <Alt-X>, or press <Esc> followed by <X>.
There are a great many commands you can use within the Info system. I have summarized the most important commands in Figure 9-8, and I will discuss them in the next few sections. As you read, it will help a lot if you start Info and follow along by testing the commands as we discuss them. When you are finished reading, you can use Figure 9-8 as a reference.
Each Info file is structured as a small tree consisting of a linear series of nodes. The purpose of each file is to cover one main idea, such as how to use a particular command; each node covers a single topic. When you start reading a file, you are placed at the root of the tree for that file. Within Info, the root of a tree is called the TOP NODE. As a general rule, the Top Node contains a summary of the topic under discussion, as well as a list of the topics covered in the file. The list is in the form of a menu. You can read the file in two ways. First, you can read the nodes in order, one after the other, from the Top Node to the last node. Alternatively, you can use the menu to jump directly to a particular node, if you want to read about a specific topic. The simplest way to read a file is to start with the Top Node and read the entire file straight through. All you have to do is press <Space>, which will display one screenful of information after another. When you get to the end of a node, pressing <Space> will take you to the beginning of the next node in the tree. Thus, you can traverse an entire tree by starting at the Top Node and pressing <Space> repeatedly. To move backwards one screenful at a time, press either <Backspace> or <Delete>. If you are at the beginning of a node and you press one of these keys, you will be taken to the previous node. (Try it.) As a convenience, you can also use <PageDown> and <PageUp> to move within a node. However, unlike the other keys, <PageDown> and <PageUp> will move only within a node, they will not move to the next or previous mode. Thus, they are handy when you want to move up and down without leaving the current node. As a convenience, you can jump to the beginning of the current node whenever you want by pressing the b key. Finally, for small movements, you can use the arrow (cursor) keys. <Down> moves the cursor down one line; <Up> moves the cursor up one line. Similarly, <Right> and <Left> move the cursor one position to the right or left respectively. To help you visualize how Info nodes and files are connected, take a look at Figure 9-9, which shows how the Info tree is organized. At first, the organization may seem complicated. However, taking a moment to understand the connections will make your work with Info a lot easier. |
|
hint The simplest way to read an Info file is to start at its Top Node and press <Space> repeatedly. In this way, you will work your way through the file, one node at a time.
As you are reading an Info file, there are several commands you can use to jump from one node to another, either within the same file or in a completely different file. To jump to the next node in the current file, press n; to jump to the previous node, press p. To jump to the Top Node (the beginning) of the current file, press t. Many nodes, especially Top Nodes, contain a list of topics in the form of a menu. Each topic is actually a link, which you can follow. Some links jump to another node within the file; other links jump to a completely different file. You will recognize links because they have a specific format: an asterisk (*), followed by the name of the topic, followed by a colon (:). After the colon, you will see a short description of the topic. Sometimes, there will also be an informative comment. Here are two examples taken from the Info tutorial I discussed above. The examples were designed to show what typical menu items look like(*):
* Foo: Help-FOO. A node you can visit for
fun.
* Footnote These examples, taken directly from the Info tutorial, show how the words "Foo" and "Bar" are used as generic names. See the discussion earlier in the chapter. The actual link is the part of the menu item between the asterisk and the colon (inclusive). It is similar to a link on a Web page. To follow a link, just move your cursor to it and press <Return>. The easiest way to do so is to press <Tab>, which moves down to the next link in the node; or M-<Tab>(*), which moves up to the previous link in the node. Alternatively, you can use the arrow keys (<Down>, <Up>, <Right> and <Left>). * Footnote As I explained earlier, M- refers to the Meta key. To use M-<Tab>, you can use either <Alt-Tab>, or press <Esc> followed by <Tab>. Regardless of how you get to a link, once you are there, all you have to do is press <Return> to make the jump. Aside from following a link, there are two other ways to jump. As we discussed earlier, each Info file is organized as a simple tree consisting of a sequence of nodes. The entire Info system, in fact, is actually one huge tree, with branches that reach directly and indirectly to every file and every node in the system. You can jump to the root of this very large tree the directory node by pressing d. Since the Directory Node acts as the main menu for the entire system, the d command is worth memorizing. The last way to jump is to press l (the letter "L") to leave the current node and return to the last node you visited. For example, let's say you have followed a link to jump from file A to file B. If you press l, you will jump back to file A. The l command is useful, because you can press it repeatedly to retrace all of your steps throughout the tree. This allows you to move backwards, one step at a time. Like the d command, the l command is worth memorizing. hint Although the Info system is complicated, there are only seven really important commands:
1. <Space>: display next screenful
If you memorize these seven commands and commit yourself to learning more as the need arises, you will do just fine.
Review Question #1: What are the two principal Unix documentation systems? What commands do you use to access each system? Review Question #2: When you are reading a man page, how do you enter a single shell command? Review Question #3: When you are looking at an Info node, which commands do you use to:
• Display the help tutorial
Applying Your Knowledge #1: Use the man command to display the man page for your default shell (man sh). Once the page is displayed, perform the following operations:
• Display the next screenful of information
Applying Your Knowledge #2: If you are using Linux or FreeBSD, use the info command to display information about the Info system itself (info info). Once the first node is displayed, perform the following operations:
• Display the next screenful of information
For Further Thought #1: The doctrine of RTFM requires people to try to help themselves by reading the documentation before asking for help. What are two advantages of this guideline? What are two disadvantages?
List of Chapters + Appendixes
© All contents Copyright 2024, Harley Hahn
|