file

cat

more

less

(Viewing Files in a Unix Environment)

All three of the programs named here allow you to see the contents of a text-file.  There is one additional command you will want to use if you are not sure if the file contains text. That command is

 file

User Commands                                             file(1)



NAME
     file - determine file type

SYNOPSIS
     file  [ -h ]  [ -m mfile ]  [ -f ffile ] file ...

     file  [ -h ]  [ -m mfile ] -f ffile

     file -c  [ -m mfile ]

DESCRIPTION
     The file  utility performs a series of tests  on  each  file
     supplied  by  file  and,  optionally, on each file listed in
     ffile in an attempt to classify it. If the  file  is  not  a
     regular  file,  its file type is identified.  The file types
     directory, FIFO, block special, and  character  special  are
     identified  as  such.  If the file is a regular file and the
     file is zero-length, it is identified as an empty file.

So what does file tell you about files?

%backup%~:      ascii text
3:              directory
3rd-Party-Seq-Anal:     directory
505-ballot.html:        ascii text

FALL96.NWS:     English text
FTP.faq:        ascii text
Mail:           directory
Moc.tar.gz:     gzip compressed data - deflate method , original file name
NRFES:          directory
NWA-94.xls:     data
Network:        cannot open: No such file or directory
Trash:          cannot open: No such file or directory
Folder:         cannot open: No such file or directory
Pangea:         directory
SeqLab.cp:      English text
SeqLabLarge:    ascii text
11sb_cucma_178.fasta:   English text
AFC1.motifs:    ascii text
GGU23823_50.pair:       English text
HSU72937_57.map:        English text
IME2-accs:      ascii text
IME2-seq:       ascii text
IME2.bak:       ascii text
IME2.seq:       English text
KNS-1.motifs:   ascii text
KNS1.motifs:    ascii text
MMU09383_48.map:        English text
N-terminus.rsf: ascii text
WormLAMMER.seq: ascii text
WormLAMMER.upload:      ascii text
a38643.seq:     ascii text
a39676.seq:     ascii text
a54099.seq:     ascii text
aa283062_82.map:        c program text
ab000905_57.figure:     [nt]roff, tbl, or eqn input text
ab000905_58.map:        ascii text
align-pretty-print:     ascii text
arab_afc3_151.figure:   [nt]roff, tbl, or eqn input text
arabidops_afc2_118.map: c program text
atts0012_176.fasta:     c program text

Looking at the list above, you can use the cat, more, or less commands to view the contents of files whose type is ascii text, English text, and c program text.  You cannot view the contents of files labeled data, directory, or "cannot open: No such file or directory" . This latter error message results when files are created with such unusual characters as spaces in them:

molbio /dr4/home4/admin/cprice> ls -la|grep Trash
drwxr-xr-x   4 cprice        512 May 30  1996 Network Trash Folder/
molbio /dr4/home4/admin/cprice> 

 

cat



cat, which stands for concatenate, will perform the same job for you as the DOS type command. It will print the contents of a file to the screen for you so that you can look at the file. It is normally used in conjunction with the pipe symbol ( | ) and the more command.

more

more behaves similarly to the more on DOS systems, except that you can precede the file name with the command, as well as use more following the | (pipe) symbol . More will display the file a single screen full at a time. 

Examples: 

    cat filename | more

and

    more filename 

Commands to use with more:

    <SPACE> will cause more to scroll through the next screen full of text.
    "q" will quit, and 
    < ENTER > will scroll through the file 1 line at a time.
    k will move your view up (backwards) 1 line at a time
    j will move your view down (forward) 1 line at a time, as does the <ENTER> key.

less

Less does everything more does, and does more things too. It uses all the same commands as more, but in addition, uses other commands to manipulate the screen that you are looking at.

Less commands are a clone of the commands in the vi editor.

A summary of the manual page for the less commands:

 
     In the following  descriptions,  ^X  means  control-X.   ESC
     stands  for  the ESCAPE key; for example ESC-v means the two
     character sequence "ESCAPE", then "v".
Line Movement Commands: 
    LEFTARROW [ ESC-h ]
          Move the cursor one space to the left.

     RIGHTARROW [ ESC-l ]
          Move the cursor one space to the right.

     ^LEFTARROW [ ESC-b or ESC-LEFTARROW ]
          (That is, CONTROL and LEFTARROW simultaneously.)   Move
          the cursor one word to the left.

     ^RIGHTARROW [ ESC-w or ESC-RIGHTARROW ]
          (That is, CONTROL and RIGHTARROW simultaneously.)  Move
          the cursor one word to the right.

     HOME [ ESC-0 ]
          Move the cursor to the beginning of the line.

     END [ ESC-$ ]
          Move the cursor to the end of the line.

     BACKSPACE
          Delete the character to the left of the cursor, or can-
          cel the command if the command line is empty.

     DELETE or [ ESC-x ]
          Delete the character under the cursor.

     ^BACKSPACE [ ESC-BACKSPACE ]
          (That  is,  CONTROL  and   BACKSPACE   simultaneously.)
          Delete the word to the left of the cursor.

     ^DELETE [ ESC-X or ESC-DELETE ]
          (That is, CONTROL and DELETE  simultaneously.)   Delete
          the word under the cursor.

     UPARROW [ ESC-k ]
          Retrieve the previous command line.

     DOWNARROW [ ESC-j ]
          Retrieve the next command line.

     TAB  Complete the partial filename to the left of  the  cur-
          sor.   If  it matches more than one filename, the first
          match is entered into the command line.  Repeated  TABs
          will  cycle  thru the other matching filenames.  If the
          completed filename is a directory, a "/" is appended to
          the  filename.  (On MS-DOS systems, a "\" is appended.)
          The environment variable LESSSEPARATOR can be  used  to
          specify  a different character to append to a directory
          name.

     BACKTAB [ ESC-TAB ]
          Like, TAB, but cycles in the reverse direction thru the
          matching filenames.

     ^L   Complete the partial filename to the left of  the  cur-
          sor.  If it matches more than one filename, all matches
          are entered into the command line (if they fit).

     ^U (Unix) or ESC (MS-DOS)
          Delete the entire command line, or cancel  the  command
          if the command line is empty.  If you have changed your
          line-kill character in Unix to something other than ^U,
          that character is used instead of ^U.

Other Commands:
     In the following  descriptions,  ^X  means  control-X.   ESC
     stands  for  the ESCAPE key; for example ESC-v means the two
     character sequence "ESCAPE", then "v".

     h or H
          Help: display a summary of these commands.  If you for-
          get all the other commands, remember this one.

     SPACE or ^V or f or ^F
          Scroll forward N lines, default one window (see  option
          -z below).  If N is more than the screen size, only the
          final screenful is displayed.   Warning:  some  systems
          use ^V as a special literalization character.

     z    Like SPACE, but if N is specified, it becomes  the  new
          window size.

     ESC-SPACE

          Like SPACE, but scrolls a full screenful,  even  if  it
          reaches end-of-file in the process.

     RETURN or ^N or e or ^E or j or ^J
          Scroll forward N lines, default 1.  The entire N  lines
          are displayed, even if N is more than the screen size.

     d or ^D
          Scroll forward N lines, default one half of the  screen
          size.   If  N  is specified, it becomes the new default
          for subsequent d and u commands.

     b or ^B or ESC-v
          Scroll backward N lines, default one window (see option
          -z below).  If N is more than the screen size, only the
	final screenful is displayed.

     w    Like ESC-v, but if N is specified, it becomes  the  new
          window size.

     y or ^Y or ^P or k or ^K
          Scroll backward N lines, default 1.  The entire N lines
          are  displayed, even if N is more than the screen size.
          Warning: some systems use ^Y as a special  job  control
          character.

     u or ^U
          Scroll backward N lines, default one half of the screen
          size.   If  N  is specified, it becomes the new default
          for subsequent d and u commands.

     ESC-) or RIGHTARROW
          Scroll horizontally  right  N  characters,  default  8.
          This  behaves  best if you also set the -S option (chop
          lines).  Note that if you wish to enter a number N, you
          must  use  ESC-),  not RIGHTARROW, because the arrow is
          taken to be a line editing command (see the LINE  EDIT-
          ING section).

     ESC-( or LEFTARROW
          Scroll horizontally left N characters, default 8.

     r or ^R or ^L
          Repaint the screen.

     R    Repaint the  screen,  discarding  any  buffered  input.
          Useful  if  the  file  is  changing  while  it is being
          viewed.

     F    Scroll forward, and keep trying to read when the end of
          file  is  reached.  Normally this command would be used
          when already at the end of the file.  It is  a  way  to
          monitor the tail of a file which is growing while it is
          being viewed.  (The behavior is similar  to  the  "tail
          -f" command.)

     g or < or ESC-<
          Go to line N in  the  file,  default  1  (beginning  of
          file).  (Warning: this may be slow if N is large.)

     G or > or ESC->
          Go to line N in the file, default the end of the  file.
          (Warning:  this  may  be slow if N is large, or if N is
          not specified and standard input, rather than  a  file,
          is being read.)

     p or %
          Go to a position N percent into the file.  N should  be
          between 0 and 100.

     {    If a  left  curly  bracket  appears  in  the  top  line
          displayed  on  the screen, the { command will go to the
          matching right curly bracket.  The matching right curly
          bracket is positioned on the bottom line of the screen.
          If there is more than one left curly bracket on the top
          line,  a  number  N  may  be  used  to specify the N-th
          bracket on the line.

     }    If a right curly bracket appears  in  the  bottom  line
          displayed  on  the screen, the } command will go to the
          matching left curly bracket.  The matching  left  curly
          bracket  is  positioned  on the top line of the screen.
          If there is more than one right curly  bracket  on  the
          top  line,  a  number N may be used to specify the N-th
          bracket on the line.

     (    Like {, but applies to parentheses  rather  than  curly
          brackets.

     )    Like }, but applies to parentheses  rather  than  curly
          brackets.

     [    Like {, but applies  to  square  brackets  rather  than
          curly brackets.

]    Like }, but applies  to  square  brackets  rather  than
          curly brackets.

     ESC-^F
          Followed by two characters, acts like {, but  uses  the
          two  characters  as  open  and  close brackets, respec-
          tively.  For example, "ESC ^F < >" could be used to  go
          forward  to  the  >  which  matches  the  <  in the top
          displayed line.

     ESC-^B
          Followed by two characters, acts like }, but  uses  the
          two  characters  as  open  and  close brackets, respec-
          tively.  For example, "ESC ^B < >" could be used to  go
          backward  to  the  <  which matches the > in the bottom
          displayed line.

     m    Followed by any lowercase  letter,  marks  the  current
          position with that letter.

     '    (Single quote.)   Followed  by  any  lowercase  letter,
          returns  to  the  position  which was previously marked
          with that letter.  Followed by  another  single  quote,
          returns to the position at which the last "large" move-
          ment command was executed.  Followed by a ^ or $, jumps
          to  the  beginning  or  end  of  the file respectively.
          Marks are preserved when a new file is examined, so the
          ' command can be used to switch between input files.

     ^X^X Same as single quote.

     /pattern
          Search forward in the file for the N-th line containing
          the  pattern.  N defaults to 1.  The pattern is a regu-
          lar expression, as recognized by ed. The search  starts
          at  the  second  line  displayed (but see the -a and -j
          options, which change this).

          Certain characters are special if entered at the begin-
          ning  of  the  pattern;  they modify the type of search
          rather than become part of the pattern:

          ^N or !
               Search for lines which do NOT match the pattern.

          ^E or *
               Search multiple files.  That  is,  if  the  search
               reaches  the END of the current file without find-
               ing a match, the search continues in the next file
               in the command line list.

          ^F or @
               Begin the search at the first line  of  the  FIRST
               file  in the command line list, regardless of what
               is currently displayed on the screen or  the  set-
               tings of the -a or -j options.

          ^K   Highlight any text which matches  the  pattern  on
               the  current  screen,  but don't move to the first
               match (KEEP current position).

          ^R   Don't interpret regular expression metacharacters;
               that is, do a simple textual comparison.

     ?pattern
          Search backward in the file for the N-th line  contain-
          ing the pattern.  The search starts at the line immedi-
          ately before the top line displayed.

          Certain characters are special as in the / command:

          ^N or !
               Search for lines which do NOT match the pattern.

          ^E or *
               Search multiple files.  That  is,  if  the  search
               reaches  the beginning of the current file without
               finding a match, the search continues in the  pre-
               vious file in the command line list.

          ^F or @
               Begin the search at the last line of the last file
               in  the  command  line list, regardless of what is
               currently displayed on the screen or the  settings
               of the -a or -j options.

          ^K   As in forward searches.

          ^R   As in forward searches.

     ESC-/pattern
          Same as "/*".

     ESC-?pattern
          Same as "?*".

     n    Repeat previous search, for N-th  line  containing  the
          last  pattern.   If the previous search was modified by
          ^N, the search is made for the N-th line NOT containing
          the  pattern.   If  the previous search was modified by
          ^E, the search continues in the next (or previous) file
          if  not satisfied in the current file.  If the previous
          search was modified by ^R, the search is  done  without
          using  regular  expressions.  There is no effect if the
          previous search was modified by ^F or ^K.

     N    Repeat previous search, but in the reverse direction.

     ESC-n
          Repeat previous search, but crossing  file  boundaries.
          The  effect  is as if the previous search were modified
          by *.

    ....