-->
Page 41
Hour
Page 42
Page 43
This hour introduces you to the basic Linux commands you'll use for navigating, searching, and reading files and directories of your file system (the directories of your Linux partition). After working through the material, you should know how to get help on commands, find out where you are in Linux, and how to find files on your hard drive. The hour starts with navigating and searching your directory, and moves on to show you how to read directories and files. But first, you'll learn how to help yourself with the man command.
One of the first things to know about Linux is that help is never far away. Like most implementations of UNIX, your Linux distribution comes with manual pages for nearly each utility, command, or programming system call. You can get information about nearly any command, including man, by typing
# man man
Manual pages started out in UNIX as one-page descriptions, available on-line, usually under the /usr/man directory. The file for each manual page is named
Page 44
with a single-digit extension, and placed in a subdirectory under /usr/man. For example, the manual page for man would be named and found as
/usr/man/man1/man.1
If you want to understand the format and placement of manual pages, you won't find this information in man.1, but in man.7 under /usr/man/man7. If you look at Table 4.1, you'll see the locations and contents of each manual section.
Table 4.1. The Linux manual sections.
Directory | Contents |
/usr/man/man1 | Commands: commands you run from within a shell |
/usr/man/man2 | System calls: documentation for kernel functions |
/usr/man/man3 | Library calls: manual pages for libc functions |
/usr/man/man4 | Special files: information about files in the /dev directory |
/usr/man/man5 | File formats: details of formats for /etc/passwd and other files |
/usr/man/man6 | Games |
/usr/man/man7 | Macro packages: descriptions of the Linux file system, man pages, and others |
/usr/man/man8 | System management: manual pages for root operator utilities |
/usr/man/man9 | Kernel routines: documentation on Linux kernel source routines |
Each manual page traditionally has a number of sections, with the documentation for the command broken down into sections. Look at Table 4.2 for the organization of a manual page.
Table 4.2. Organization of a manual page.
Section | Description |
NAME | The name of the command and a brief description |
SYNOPSIS | How to use the command and command-line options |
DESCRIPTION | An explanation of the program and its options |
FILES | A list of files used by command, and their location |
SEE ALSO | A list of related man pages |
DIAGNOSTICS | A description of unusual output |
BUGS | Known problems |
AUTHOR | The program's main author and other contributors |
Page 45
Online manual pages contain special typesetting codes for the nroff text formatting program (see Hour 15, "Preparing Documents"), using special macros (as documented in man.7). This format is critically important for other programs, such as makewhatis, whatis, and apropos, which you'll learn about later in this chapter.
You can also find more detailed documentation for Linux commands and other subjects under the /usr/doc directory, which contains files called Frequently Asked Questions, or FAQs, and HOWTOs, or How-To documents. Additionally, the Free Software Foundation, which releases the GNU software packages (many of the commands discussed in this book are GNU programs), puts much of its documentation in a special hypertext "info" format.
JUST A MINUTE |
Much of the software for Linux comes from the Free Software Foundation, or FSF, founded by Richard Stallman, author of the emacs editor (see Hour 14, "Text Processing"). The FSF distributes its software under the GNU General Public License, or GPL. Part of the success and popularity of Linux and GNU software is because of the terms of the GPL. If you want more information about the GNU software programs for Linux, the FSF, or the GNU GPL, you can try the info command, which is a reader for the GNU hypertext documentation, found under the /usr/info directory. |
The man command normally searches for manual pages according to instructions detailed in the man.config file under the /etc directory. These instructions define the default directories in which to look for manual pages, and they match the directories to the $MANPATH environment variable, an abbreviated string of characters defined when you first start Linux and log in. Environment variables are discussed in Hour 6, "Using the Shell." The default places to look for these pages are
MANPATH /usr/man MANPATH /usr/local/man MANPATH /usr/X11R6/man MANPATH /usr/lib/perl5/man
Just a Minute |
A graphic version of the man command, called xman, is available for the X Window System. You can use xman not only to read manual pages, but to see directories of manual page entries. The xman program is handy and many users keep its small menu window active on their desktops. |
Page 46
This section introduces you to the basic navigation commands, and shows you how to move around your Linux file system, find files, and build file information databases, such as those for use with the whatis command. You'll also learn about alternative approaches and programs, and how to speed up searches to find files quickly.
The cd (change directory) command is the basic navigation tool for moving your current location to different parts of the Linux file system. You can move directly to a directory by typing the command, followed by a pathname or directory. For example, the following command will move you to the /usr/bin directory:
# cd /usr/bin
When you're in that directory, you can move up to the /usr directory with the following command:
# cd ..
You could also move to the root directory, or /, while in the /usr/bin directory by using the following command:
# cd ../..
Finally, you can always go back to your home directory (where your files are) by using either of the following commands:
# cd
or
# cd ~
Note that if you try to use the man command to read the cd man page, you won't find one. Why? Because cd is built into the shell. See bash in Hour 6, for more details.
The pwd (print working directory) command tells you where you are, and prints the working (current) directory. For example, if you execute
# cd /usr/bin
and then type
# pwd