Looking Inside Files

You've learned how to manipulate files and directories, so now it's time to find out what kind of information is contained within these files and look inside the files.

Task 7.1: Using file to Identify File Types

One of the most undervalued commands in UNIX is file, which is often neglected and collecting dust in some corner of the system. The file command is a program that can easily offer you a good hint as to the contents of a file by looking at the first few lines.


Unfortunately, there is a problem with the file command: It isn't 100% accurate. The program relies on a combination of the permissions of a file, the filename, and an analysis of the first few lines of the text. If you had a text file that started out looking like a C program or that had execute permission enabled, file might well identify it as an executable program rather than an English text file.

You can determine how accurate your version of file is by checking the size of its database of file types. You can do this with the UNIX command wc -l /etc/magic. The number of entries in the database should be around 100. If you have many fewer than this number, you're probably going to have trouble. If you have considerably more, you might have a very accurate version of file at your fingertips! Remember, however, that even if it's relatively small, file can still offer invaluable suggestions regarding file content.


  1. Start by logging in to your account and using the ls command to find a file or two to check:

    % ls -F
    Archives/               OWL/                    rumors.26Oct.Z
    InfoWorld/              PubAccessLists.Z        rumors.5Nov.Z
    LISTS                   bin/                    src/
    Mail/                   educ                    temp/
    News/                   mailing.lists.bitnet.Z
    

    Next, simply enter the file command, listing each of the files you'd like the program to analyze:

    % file LISTS educ rumors.26Oct.Z src
    LISTS:  ascii text
    educ:   ascii text
    rumors.26Oct.Z: block compressed 16 bit code data
    src:    directory
    

    From this example, you can see that file correctly identifies src as a directory, offers considerable information on the compressed file rumors.26Oct.Z, and tags both LISTS and educ as plain ASCII text files.

ASCII is the American Standard Code for Information Interchange, and it means that the file contains the letters of the English alphabet, punctuation, and numbers, but not much else. There are no multiple typefaces, italics, or underlined passages, and there are no graphics. It's the lowest common denominator of text in UNIX.


  1. Now try using the asterisk (*), a UNIX wildcard (wildcards are explained in Hour 9, “Wildcards and Regular Expressions”), to have the program analyze all files in your home directory:

    % file *
    Global.Software:        English text
    Interactive.Unix:       mail folder
    Mail:           directory
    News:           directory
    Src:            directory
    bin:            directory
    history.usenet.Z:       compressed data block compressed 16 bits
    

    The asterisk (*) is a special character in UNIX. Used by itself, it tells the system to replace it with the names of all the files in the current directory.

    This time you can begin to see how file can help differentiate files. Using this command, I am now reminded that the file Global.Software is English text, but Interactive.Unix is actually an old electronic mail message (file can't differentiate between a single mail message and a multiple-message folder, so it always errs on the side of saying that the file is a mail folder).

  2. Mail folders are actually problematic for the file command. On one of the systems I use, the file command doesn't know what mail messages are, so asking it to analyze mail folders results in a demonstration of how accuracy is related to the size of the file database.

    On a Sun system, I asked file to analyze two mail folders, with the following results:

    % file Mail/mailbox Mail/sent
    Mail/mailbox:   mail folder
    Mail/sent: mail folder
    

    Those same two files on a Berkeley UNIX system, however, have very different results when analyzed:

    % file Mail/mailbox Mail/sent Mail/netnews
    Mail/mailbox:        ascii text
    Mail/sent:       shell commands
    Mail/netnews:       English text
    

    Not only does the Berkeley version of UNIX not identify the files correctly, but it doesn't even misidentify them consistently.

  3. Another example of the file command's limitations is how it interacts with file permissions. Use cp to create a new file and work through this example to see how your file command interprets the various changes:

    % cp .cshrc test
    % file test
    test: shell commands
    % chmod +x test
    % file test
    test: shell script
    

    Adding execute permission to this file caused file to identify it as a shell script rather than shell commands.

Don't misinterpret the results of these examples as proof that the file command is useless and that you shouldn't use it. Quite the opposite is true. UNIX has neither a specific file-naming convention (Windows has its three-letter filename suffixes) nor indication of file ownership by icon (Macintosh does this with creator information added by each program). As a result, it's vital that you have a tool for helping ascertain file types without actually opening the file.


Why not just look at the contents? The best way to figure out the answer to this question is to display accidentally the contents of an executable file on the screen. You'll see it's quite a mess, loaded with special control characters that can be best described as making your screen go berserk.

Task 7.2: Exploring UNIX Directories with file

Now that you know how to work with the file command, it's time to wander through the UNIX file system, learning more about types of files that tend to be found in specific directories. Your system might vary slightly—it'll certainly have more files in some directories than what I'm showing here in the examples, but you'll quickly see that file can offer some valuable insight into the contents of files.


  1. First things first. Take a look at the files found in the very top level of the file system, in / (slash):

    % cd /
    % ls -CF
    -No _rm_ star  boot         flags/       rhf@         userb/
    OLD/           core         gendynix     stand/       userc/
    archive/       dev/         lib@         sys@         userd/
    ats/           diag@        lost+found/  tftpboot@    usere/
    backup/        dynix        mnt/         tmp/         users/
    bin@           etc/         net/         usera/       usr/
    % file boot core gendynix tftpboot
    boot:   SYMMETRY i386 stand alone executable version 1
    core:   core from getty
    gendynix:       SYMMETRY i386 stand alone executable not stripped version 1
    tftpboot:       symbolic link to /usr/tftpboot
    

    This example is from a Sequent computer running DYNIX, the Sequent's version of UNIX, based on Berkeley 4.3 BSD with some AT&T System V extensions. It's the same machine that has such problems identifying mail folders.

    Executable binaries are explained in detail by the file command on this computer: boot is listed as SYMMETRY i386 stand alone executable version 1. The specifics aren't vital to understand: The most important word to see in this output is executable, indicating that the file is the result of compiling a program. The format is SYMMETRY i386, version 1, and the file requires no libraries or other files to execute—it's standalone.

    For gendynix, the format is similar, but one snippet of information is added that isn't indicated for boot: The executable file hasn't been stripped.

    When a program dies unexpectedly in UNIX, the operating system tries to leave a snapshot of the memory that the program was using, to aid in debugging. Wading through these core files can be quite difficult—it's usually reserved for a few experts at each site—but there is still some useful information inside. The best, and simplest, way to check it is with the file command. You can see in the preceding listing that file recognized the file core as a crashed program memory image and further extracted the name of the program, getty, that originally failed, causing the program to fail. When this failure happens, UNIX creates an image of the program in memory at the time of failure, which is called a core dump.

    The fourth of the listings offers an easy way to understand symbolic links, indicated in ls -CF output with the special suffix @, as shown in the preceding example with tftpboot@. Using file, you can see that the file tftpboot in the root directory is actually a symbolic link to a file with the same name elsewhere in the file system, /usr/tftpboot.

Stripping a file doesn't mean that you peel its clothes off, but rather that various information included in most executables to help identify and isolate problems has been removed to save space.


  1. There are differences in output formats on different machines. The following example shows what the same command would generate on a Sun Microsystems workstation, examining analogous files:

    % file boot core kadb tmp
    boot:           sparc executable
    core:           core file from 'popper'
    kadb:           sparc executable not stripped
    tmp:            symbolic link to /var/tmp
    

    The Sun computer offers the same information, but fewer specifics about executable binaries. In this case, Sun workstations are built around SPARC chips (just like PCs are built around Intel chips), so the executables are identified as sparc executable.

  2. Are you ready for another directory of weird files? It's time to move into the /lib directory to see what's there.

    Entering ls will demonstrate quickly that there are a lot of files in this directory! The file command can tell you about any of them. On my Sun computer, I asked for information on a few select files, many of which you might also have on yours:

    % file lib.b lib300.a diffh sendmail
    lib.b:          c program text
    lib300.a:       archive random library
    diffh:          sparc pure dynamically linked executable not stripped
    sendmail:       sparc demand paged dynamically linked set-uid executable
    

    The first file, lib.b, demonstrates that the file command works regardless of the name of a file: Standard naming for C program files specifies that they end with the characters .c, as in test.c. So, without file, you might never have suspected that lib.b is a C program. The second file is an actual program library and is identified here as an archive random library, meaning that it's an archive and that the information within can be accessed in random order (by appropriate programs).

    The third file is an executable, demonstrating another way that file can indicate programs on a Sun workstation. The sendmail program is an interesting program: It's an executable, but it has some new information you haven't seen before. The set-uid indicates that the program is set up so that when anyone runs it, sendmail runs as the user who owns the file, not the user who launched the program. A quick ls can reveal a bit more about this:

    % ls -l /lib/sendmail
    -r-sr-x--x  1 root       155648 Sep 14 09:11 /lib/sendmail*
    

    Notice here that the fourth character of the permissions string is an s rather than the expected x for an executable. Also check the owner of the file in this listing. Combined, the two mean that when anyone runs this program, sendmail actually will set itself to a different user ID (root in this case) and have that set of access permissions. Having sendmail run with root permissions is how you can send electronic mail to someone else without fuss, but you can't view his or her mailbox.

The good news is that you don't have to worry a bit about what files are in /lib, /etc, or any other directory other than your own home directory. Thousands of happy UNIX folk work busily away each day without ever realizing that these other directories exist, let alone knowing what's in them.


What's important here is that you have learned that the file command is quite sophisticated at identifying special UNIX system files of various types. It can be a very helpful tool when you are looking around in the file system and even just when you are trying to remember which files are which in your own directory.

Task 7.3: Peeking at the First Few Lines with head

Now that you have the tools needed to move about in the file system, to double-check where you are, and to identify the different types of files, it's time to learn about some of the many tools UNIX offers for viewing the contents of files. The first on the list is head, a simple program for viewing the first 10 lines of any file on the system.


The head program is more versatile than it sounds: You can use it to view up to the first few hundred lines of a very long file, actually. To specify the number of lines you want to see, you just need to indicate how many as a starting argument, prefixing the number of lines desired with a dash.

This command, head, is the first of a number of UNIX commands that tend to work with their own variant on the regular rules of starting arguments. Instead of a typical UNIX command argument of -l33 to specify 33 lines, head uses -33 to specify the same information.


  1. Start by moving back into your home directory and viewing the first few lines of your .cshrc file:

    % cd
    % head .cshrc
    #
    # Default user .cshrc file (/bin/csh initialization).
    
    set host=limbo
    
    set path=(. ~/bin /bin /usr/bin /usr/ucb /usr/local /etc
    /usr/etc/usr/local/bin /usr/unsup/bin)
    
    # Set up C shell environment:
    
    alias  diff     '/usr/bin/diff -c -w'
    

    The contents of your own .cshrc file will doubtless be different, but notice that the program lists only the first few lines of the file.

  2. To specify a different number of lines, use the -n format (where n is the number of lines). I'll look at just the first four lines of the .login file:

    % head -4 .login
    #
    # @(#) $Revision: 62.2 $
    
    setenv TERM vt100
    
  3. You also can easily check multiple files by specifying them to the program:

    % head -3 .newsrc /etc/passwd
    ==> .newsrc <==
    misc.forsale.computers.mac: 1-14536
    utech.student-orgs! 1
    general! 1-546
    
    ==> /etc/passwd <==
    root:?:0:0: root,,,,:/:/bin/csh
    news:?:6:11:USENET News,,,,:/usr/spool/news:/bin/ksh
    ingres:*?:7:519:INGRES Manager,,,,:/usr/ingres:/bin/csh
    
  4. More importantly, head, and other UNIX commands, can work also as part of a pipeline, where the output of one program is the input of the next. The special symbol for creating UNIX pipelines is the pipe character (|). Pipes are read left to right, so you can easily have the output of who, for example, feed into head, offering powerful new possibilities. Perhaps you want to see just the first five people logged in to the computer right now. Try this:

    % who | head -5
    root     console Nov  9 07:31
    mccool   ttyaO   Nov 10 14:25
    millekl2 ttyaP   Nov 10 14:58
    paulwhit ttyaR   Nov 10 14:50
    bobweir  ttyaS   Nov 10 14:49
    Broken pipe
    

    Pipelines are one of the most powerful features of UNIX, and there are many examples of how to use them to best effect throughout the remainder of this book.

  5. Here is one last thing. Find an executable—/boot will do fine—and enter head -1 /boot. Watch what happens. Or, if you'd like to preserve your sanity, take it from me that the random junk thrown on your screen is plenty to cause your program to get quite confused and possibly even quit or crash.

    The point isn't to have that happen to your screen, but rather to remind you that using file to confirm the file type for unfamiliar files can save you lots of grief and frustration!

The simplest of programs for viewing the contents of a file, head, is easy to use, is efficient, and works as part of a pipeline too. The remainder of this hour focuses on other tools in UNIX that offer other ways to view the contents of text and ASCII files.


Task 7.4: Viewing the Last Few Lines with tail

The head program shows you the first 10 lines of the file you specify. What would you expect tail to do, then? I hope you guessed the right answer: It shows the last 10 lines of a file. Like head, tail also understands the same format for specifying the number of lines to view.


  1. Start out viewing the last 12 lines of your .cshrc file:

    % tail -12 .cshrc
    
      set noclobber history=100 system=filec
      umask 007
      setprompt
    endif
    
    # special aliases:
    
    alias info      ssinfo
    alias ssinfo    'echo "connecting..." ; rlogin oasis'
    
  2. Next, the last four lines of the file LISTS in my home directory can be shown with the following command line:

    % tail -5 LISTS
              College of Education
              Arizona State University
              Tempe, AZ 85287-2411
              602-965-2692
    

    Don't get too hung up trying to figure out what's inside my files; I'm not even sure myself sometimes.

  3. Here's one to think about. You can use head to view the first n lines of a file, and tail to view the last n lines of a file. Can you figure out a way to combine the two so that you can see just the 10th, 11th, and 12th lines of a file?

    % head -12 .cshrc | tail -3
    alias  diff     '/usr/bin/diff -c -w'
    alias  from     'frm -n'
    alias  ll       'ls -l'
    

    It's easy with UNIX command pipelines!

Combining the two commands head and tail can give you considerable power in viewing specific slices of a file on the UNIX system. Try combining them in different ways for different effects.


Task 7.5: Viewing the Contents of Files with cat

Both head and tail offer the capability to view a piece of a file, either the top or the bottom, but neither lets you see the entire file, regardless of length. For this job, the cat program is the right choice.


The cat program got its name from its function in the early versions of UNIX; its function was to concatenate (or join together) multiple files. It isn't, unfortunately, an homage to feline pets or anything else so exotic!


The cat program also has a valuable secret capability: Through use of the -v flag, you can use cat to display any file on the system, executable or otherwise, with all characters that normally would not be printed (or would drive your screen bonkers) displayed in a special format I call control key notation. In control key notation, each character is represented as ^n, where n is a specific printable letter or symbol. A character with the value of zero (also referred to as a null or null character) is displayed as ^@, a character with the value 1 is ^A, a character with the value 2 is ^B, and so on.

Another cat flag that can be useful for certain files is -s, which suppresses multiple blank lines from a file. It isn't immediately obvious how that could help, but there are some files that can have a screenful (or more) of blank lines. To avoid having to watch them all fly past, you can use cat -s to chop 'em all down to a single blank line.

  1. Move back to your home directory again, and use cat to display the complete contents of your .cshrc file:

    								% cd
    % cat .cshrc
    #
    # Default user .cshrc file (/bin/csh initialization).
    
    set path=(. ~/bin /bin /usr/bin /usr/ucb /usr/local /etc
    /usr/etc/usr/local/bin /usr/unsup/bin )
    
    # Set up C shell environment:
    
    alias  diff     '/usr/bin/diff -c -w'
    alias  from     'frm -n'
    alias  ll       'ls -l'
    alias  ls       '/bin/ls -F'
    alias  mail     Mail
    alias  mailq    '/usr/lib/sendmail -bp'
    
    alias  newaliases 'echo you mean newalias...'
    
    alias  rd       'readmsg $ | page'
    alias  rn       '/usr/local/bin/rn -d$HOME -L -M -m -e -S -/'
    
    # and some special stuff if we're in an interactive shell
    
    if ( $?prompt ) then            # shell is interactive.
    
      alias  cd             'chdir !* ; setprompt'
      alias  env            'printenv'
      alias  setprompt      'set prompt="$system ($cwd:t) ! : "'
    
      set noclobber history=100 system=limbo filec
      umask 007
      setprompt
    endif
    
    # special aliases:
    
    alias info      ssinfo
    alias ssinfo    'echo "connecting..." ; rlogin oasis'
    

    Don't be too concerned if the content of your .cshrc file (or mine) doesn't make any sense to you. You are slated to learn about the content of this file within a few hours, and, yes, it is complex.

    You can see that cat is pretty simple to use. If you specify more than one filename to the program, it lists the filenames in the order you specify. You can even list the contents of a file multiple times by specifying the same filename on the command line multiple times.

  2. The cat program also can be used as part of a pipeline. Compare the following command with my earlier usage of head and tail:

    % cat LISTS | tail -5
              College of Education
              Arizona State University
              Tempe, AZ 85287-2411
              602-965-2692
    
  3. Now find an executable file, and try cat -v in combination with head to get a glimpse of the contents therein:

    % cat -v /bin/ls | head -1
    M-k"^@^@^@M-^@^@^@^@^P^@^@M-45^@^@^@^@^@^@M-l^P^@^@^@^@^@^@ ^@^@^@^@^@^@^@^@
    ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ^@^@^@^@^@^@^@^@^@
    ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ ^@^@^@^@^@^@^@^@
    ^@^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@$Header: crt0.c 1.4 87/04/23 $^@^@@(#)Copy
    right (C) 1984 XXXXXXX Computer Systems, Inc.  All rights reserved. ^@M-^KM-NM-^KM-
    tM-^MF^DM-^KM-XM-^K^F@M-^M^DM-^E^@^@^@^@M-^KM-S^AM-BM-^I^U^@M-^@^@ ^@SM-^?6M-hw^T^@^@M-
    ^CM-D^HM-^?5^@M-^@^@^@SM-^?6M-h&^@^@^@M-^CM-D^LPM-h)[^@^@YM-tM-^PM- ^PM-^PM-k^BM-IM-CUM-
    ^KM-lM-kM-yM-^PM-^PM-^PM
    -k^BM-IM-CUM-^KM-lM-kM-yM-^PM-^PM-^PUM-^KM-lM-^CM-l^XWVSM-^K u^LM-^K]^HKM-^CM-F^DM-hM
    -X^V^@^@M-^EM-@u^FM-^?^EM-lM-^L^@^@h^DM-^M^@^@M-hM-P7^@^ @YM-^K^E^DM-^M^@^@-^@NM-
    m^@M-^I^E^HM-^M^@^@M-^K^E^DM-^M^@^@^E^P^N^@^@M-^I^E^LM-^ M^@^@M-^C^E^DM-^M^@^@<M-
    G^E^PM-^M^@^@P^@^@^@j^AM-hM-%[^@^@YM-^EM-@tNh^TM-^M^@^@h M-HM-^J^@^@M-h12^@^@M-^C
    M-D^HM-G^EM-pM-^L^@^@^A^@^@^@M-8^A^@^@^@M-^I^EM-hM-^L^@^ @M-ht^S^@^@M-^MEM-nPj^AM
    -h]^V^@^@M-^CM-D^H^OM-?EM-r%^@^L^@^@=^@Broken pipe
    

    This is complex and confusing, indeed! What's worse, this isn't the entire first line of the executable. You know that this is so because this block of data ends with Broken pipe, which indicates that a lot more was being fed to head than it could process due to the constraint of having only the first line listed—a line that head defines as no more than 512 characters long.

The cat command is useful for viewing files and is quite easy to use. The problem with it is that if the file you choose to view has more lines than the number of lines on your screen, the file will just fly past you without your having any way to slow it down. That's where the next two commands come in handy: more for stepping through files, and page for paging through files. Both solve this problem, albeit in slightly different ways.


Task 7.6: Viewing Larger Files with more

You can now wander about the file system, find files that might be of interest, check their type with file, and even view them with the cat command, but what if they're longer than the size of your screen? That's the job of the more program, a program that knows how big your screen is and displays the information page by page.


There are three primary flags in more:

-s Suppresses multiple blank lines, just like the -s flag to cat
-d Forces more to display friendlier prompts at the bottom of each page
-c Causes the program to clear the screen before displaying each screenful of text

The program also allows you to start at a specific lin2e in the file by using the curious +n notation, where n is a specific number. Finally, you can start also at the first occurrence of a specific pattern by specifying that pattern to the program in a format similar to +/pattern (patterns are defined in Hour 9).

  1. View the .cshrc file using more:

    % more ~/.cshrc
    #
    # Default user .cshrc file (/bin/csh initialization).
    
    set host=limbo
    
    set path=(. ~/bin /bin /usr/bin /usr/ucb /usr/local /etc
    /usr/etc /usr/local/bin /usr/unsup/bin)
    
    # Set up C shell environment:
    
    alias  diff     '/usr/bin/diff -c -w'
    alias  from     'frm -n'
    alias  ll       'ls -l'
    alias  ls       '/bin/ls -F'
    alias  mail     Mail
    alias  mailq    '/usr/lib/sendmail -bp'
    
    alias  newaliases 'echo you mean newalias...'
    
    alias  rd       'readmsg $ | page'
    --More--(51%)
    

    Unlike with previous examples, where the program runs until completed, leaving you back on the command line, more is the first interactive program you've encountered. When you see the --More--(51%) prompt, the cursor sits at the end of that line, waiting for you to tell it what to do. The more program lets you know how far into the file you've viewed, too; in the example, you've seen about half of the file (51%).

    At this point, quite a variety of commands are available. Press the spacebar to see the next screen of information, until you have seen the entire file.

  2. Try starting the program with the 12th line of the file:

    % more +12 ~/.cshrc
    alias  mailq    '/usr/lib/sendmail -bp'
    
    alias  newaliases 'echo you mean newalias...'
    
    alias  rd       'readmsg $ | page'
    alias  rn       '/usr/local/bin/rn -d$HOME -L -M -m -e -S -/'
    
    # and some special stuff if we're in an interactive shell
    
    if ( $?prompt ) then            # shell is interactive.
    
      alias  cd             'chdir !* ; setprompt'
      alias  env            'printenv'
      alias  setprompt      'set prompt="$system ($cwd:t) ! : "'
    
      set noclobber history=100 filec
      umask 007
      setprompt
    endif
    --More--(82%)
    
  3. You can see that about halfway through the .cshrc file there is a line that contains the word newaliases. I can start more so that the line with this pattern is displayed on the top of the first screenful:

    % more +/newaliases ~/.cshrc
    
    ...skipping
    alias  mailq    '/usr/lib/sendmail -bp'
    
    alias  newaliases 'echo you mean newalias...'
    
    alias  rd       'readmsg $ | page'
    alias  rn       '/usr/local/bin/rn -d$HOME -L -M -m -e -S -/'
    
    # and some special stuff if we're in an interactive shell
    
    if ( $?prompt ) then            # shell is interactive.
    
      alias  cd             'chdir !* ; setprompt'
      alias  env            'printenv'
      alias  setprompt      'set prompt="$system ($cwd:t) ! : "'
    
      set noclobber history=100 filec
      umask 007
    
      setprompt
    endif
    
    # special aliases:
    
    alias info      ssinfo
    --More--(86%)
    

    Actually, notice that the line containing the pattern newaliases shows up as the third line of the first screen, not the first line. That's so that you have a bit of context to the matched line, but it can take some getting used to. Also note that more tells us—with the message ...skipping as the first line—that it's skipping some lines to find the pattern.

  4. The range of commands available at the --More-- prompt is quite extensive, as listed in Table 7.1. The sidebar following the table explains what the conventions used in the table mean and how to enter the following commands.

Table 7.1. Commands Available Within the MORE Program
Command Function
[Space] Press the spacebar to display the next screenful of text.
n[Return] Display the next n lines (the default is the next line only of text).
h Display a list of commands available in the more program.
d Scroll down half a page.
q Quit the more program.
ns Skip forward n lines (default is 1).
nf Skip forward n screenfuls (default is 1).
b or Control-b Skip backward a screenful of text.
= Display the current line number.
/pattern Search for an occurrence of a pattern.
n Search for the next occurrence of the current pattern.
v Start the vi editor at the current line.
Control-l (That's a lowercase L.) Redraw the screen.
:f Display the current filename and line number.

Entering Commands in the More Program

In this table and in the following text, [Space] (the word space enclosed in brackets) refers to pressing the spacebar as a command. Likewise, [Return] means you should press the Return key as part of the command.

A hyphen in a command—for example, Ctrl-B—means that you should hold down the first indicated key while you press the second key. The lowercase-letter commands in the table indicate that you should press the corresponding key, the A key for the a command, for example.

Two characters together, but without a hyphen (:f), mean that you should press the appropriate keys in sequence as you would when typing text.

Finally, entries that have an n before the command mean that you can prefix the command with a number, which will let it use that value to modify its action. For example, 3[Return] displays the next three lines of the file, and 250s skips the next 250 lines. Typically, pressing Return after typing a command within more is not necessary.


Try some commands on a file of your own. A good file that will have enough lines to make this interesting is /etc/passwd:

% more /etc/passwd
root:?:0:0: root:/:/bin/csh
news:?:6:11:USENET News:/usr/spool/news:/bin/ksh
ingres:*?:7:519:INGRES Manager:/usr/ingres:/bin/csh
usrlimit:?:8:800:(1000 user system):/mnt:/bin/false
vanilla:*?:20:805:Vanilla Account:/mnt:/bin/sh
charon:*?:21:807:The Ferryman:/users/tomb:
actmaint:?:23:809: Maintenance:/usr/adm/actmaint:/bin/ksh
pop:*?:26:819:,,,,:/usr/spool/pop:/bin/csh
lp:*?:70:10:System V Lp Admin:/usr/spool/lp:
trouble:*?:97:501:Trouble Report Facility:/usr/trouble:/usr/msh
postmaster:?:98:504:Mail:/usr/local/adm:/bin/csh
aab:?:513:1233:Robert Townsend:/users/aab:/bin/ksh
billing:?:516:1233:Accounting:/users/billing:/bin/csh
aai:?:520:1233:Pete Cheeseman:/users/aai:/bin/csh
--More--(1%) 60s

...skipping 60 lines

cq:?:843:1233:Rob Tillot:/users/cq:/usr/local/bin/tcsh
robb:?:969:1233:Robb:/users/robb:/usr/local/lib/msh
aok:?:970:1233:B Jacobs:/users/aok:/usr/local/lib/msh
went:?:1040:1233:David Math:/users/went:/bin/csh
aru:?:1076:1233:Raffie:/users/aru:/bin/ksh
varney:?:1094:1233:/users/varney:/bin/csh
brandt:?:1096:1233:Eric Brand:/users/brand:/usr/local/bin/tcsh
ask:?:1098:1233:/users/ask:/bin/csh
asn:?:1101:1233:Ketter Wesley:/users/asn:/usr/local/lib/msh
--More--(2%)

This example isn't exactly what you'll see on your screen, because each time you type a command to more, it erases its own prompt and replaces the prompt with the appropriate line of the file. Try pressing [Return] to move down one line, and you'll see what I mean.

Quit more in the middle of viewing this file by typing q.

The more program is one of the best general-purpose programs in UNIX, offering an easy and powerful tool for perusing files.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset