-->

Previous | Table of Contents | Next

Page 50

do. But what if you want to do something and can't remember which program does what? In this case, you can turn to the apropos command.

For example, if you can't remember which command searches for files, you can enter


# apropos search

apropos (1)          - search the whatis database for strings

badblocks (8)        - search a device for bad blocks

bsearch (3)          - binary search of a sorted array.

conflict (8)         - search for alias/password conflicts

find (1)             - search for files in a directory hierarchy

hcreate, hdestroy, hsearch (3) - hash table management

lfind, lsearch (3)   - linear search of an array.

lkbib (1)            - search bibliographic databases

lookbib (1)          - search bibliographic databases

lsearch (n)          - See if a list contains a particular element

manpath (1)          - determine user's search path for man pages

strpbrk (3)          - search a string for any of a set of characters

strspn, strcspn (3)  - search a string for a set of characters

tsearch, tfind, tdelete, twalk (3) - manage a binary tree

whatis (1)           - search the whatis database for complete words.

zgrep (1)            - search possibly compressed files for a regular expression

zipgrep (1)          - search possibly zip files for a regular expression

You'll see a list of programs from the whatis database on your screen. The apropos command uses this database to search for the keyword you entered. If you keep your manual pages and whatis database up-to-date, you'll be able to use apropos to help you find the program you need.

JUST A MINUTE
You can also use the man command's -K option to do the same thing as apropos, but the search will be slow, and you'll be presented each manual page in the search result. For example, to search for any programs dealing with PostScript, you can try

# man -K PostScript

This can result in the following output (before you quit with q):

/usr/dt/man/man5/DtStdAppFontNames.5? [ynq] n

/usr/dt/man/man4/dtdtsfile.4? [ynq] n

/usr/man/man7/unicode.7? [ynq] n

/usr/man/man7/suffixes.7? [ynq] n

/usr/man/man7/groff_char.7? [ynq] n

/usr/man/man1/convert.1x? [ynq] n

/usr/man/man1/xv.1? [ynq] n

/usr/man/man1/xdvi.1? [ynq] n

/usr/man/man1/dvips.1? [ynq] n

/usr/man/man1/afm2tfm.1? [ynq] n

/usr/man/man1/ps2pk.1? [ynq] n

/usr/man/man1/ps2frag.1? [ynq] q

Page 51

Reading Directories and Files

Now that you know about directory navigation, searching for files, or how to find more information about programs, I'll introduce you to other basic Linux commands you can use. This section shows you how to list the contents of directories, make a catalog of your hard drive, and read the contents of files. You'll learn the basic forms of these commands to help get you started.

Listing Directories with the ls Command

The ls (list directory) command will quickly become one of your most often used programs. In its simplest form, ls lists nearly all of the files in the current directory. But this command, which has such a short name, probably has more command-line options (more than 75 at last count) than any other program!

In the simple form, ls lists your files:


# ls

News          axhome        nsmail        search

author.msg    documents     reading       vultures.msg

auto          mail          research

You can also list the files as a single line, with comma separations, with the -m option:


# ls -m

News, author.msg, auto, axhome, documents, mail, nsmail, reading,

 research, search, vultures.msg

If you don't like this type of listing, you can have your files sorted horizontally, instead of vertically (the default), with the -x option:


# ls -x

News          axhome        nsmail        search

author.msg    documents     reading       vultures.msg

auto          mail          research

But are all these just files, or are there several directories? One way to find out is to use the -F option:


# ls -F

News/         axhome/       nsmail/       search*

author.msg    documents/    reading/      vultures.msg

auto/         mail/         research/

As you can see, the -F option causes the ls command to show the directories, each with a / character appended to the filename. The asterisk (*) shows that the file search is an executable program. But are these all the files in this directory? If you want to see everything, you can use the -a option with -F, as follows:


# ls -aF

./                 .dt/               .neditdb           auto/

../                .dtprofile*        .netscape/         axhome/

Page 52


.Xauthority        .festival_history  .newsrc            documents/

.Xdefaults         .forward           .oldnewsrc         mail/

.addressbook       .fvwm2rc95*        .pinerc            nsmail/

.addressbook.lu    .index/            .procmail/         reading/

.bash_history      .mailcap           .procmailrc        research/

.bash_logout       .mailrc            .tin/              search*

.bash_profile      .mime.types        .xinitrc*          vultures.msg

.bashrc            .ncftp/            News/

.desksetdefaults   .nedit             author.msg

Using the -F option is one way to see the files and directories in your listings, but if you have a color monitor, or use X11 in color, you can tell ls to show files, directories, or executable files in different colors. To do this, use the --color option. In X11, using the rxvt terminal, directories will be blue, programs will be green, and regular files will be black. You can also customize which colors are used for different types of files.

Look in the /etc/ directory for the file named DIR_COLORS. Copy this file, renaming it to .dir_colors, and save it in your home directory. You can then edit this file to customize or add file types recognized for colorizing. See the DIR_COLORS file for details.

Long Directory Listing

Would you like even more information about your files? You can view the long format listing by using the ls -l option, for example:


# ls -l

drwxr-xr-x   2 bball    bball        1024 Nov 12 08:20 News

-rw-rw-r--   1 bball    bball        4766 Nov 12 07:41 author.msg

drwxrwxr-x   2 bball    bball        1024 Nov  5 10:04 auto

drwxrwxr-x   3 bball    bball        1024 Nov 12 13:54 axhome

drwxrwxr-x   2 bball    bball        1024 Nov 12 14:33 documents

drwx------   2 bball    bball        1024 Nov 12 14:02 mail

drwx------   2 bball    bball        1024 Sep 15 01:57 nsmail

drwxrwxr-x   2 bball    bball        1024 Oct 29 20:28 reading

drwxrwxr-x   5 bball    bball        1024 Nov  5 10:03 research

-rwxrwxr-x   1 bball    bball         200 Oct 24 13:24 search

-rw-rw-r--   1 bball    bball         801 Nov 11 22:46 vultures.msg

As you can see, there are eight different columns. The first column is the file's permissions flags, which are covered in Hour 21, "Handling Files." These flags generally show the file's type, and who can read, write (or modify or delete), or run the file. The next column shows the number of links, which are discussed in Hour 5, "Manipulation and Searching Commands." Next is the owner name, followed by group name. Owners and groups are discussed in Hour 21. The file size is listed next, followed by a timestamp of the file or directory was created or last modified. The last column, obviously, is each file's name.

Previous | Table of Contents | Next