Previous Table of Contents Next


RELATED COMMANDS

Refer to modules 24, 103, and 105 for descriptions of the cp, pg, and pr commands.

RELATED FILES

The cat command is a filter; therefore, it can read the standard input and write to the standard output.

APPLICATION

The cat command can be used to concatenate files together, display the contents of files, and copy files. The concatenation of files is joining one file to the end of another. Displaying files is sending the data to your terminal screen. Copying files is done in conjunction with the shell’s redirection capabilities.

Other commands have been designed to provide enhanced functions of cat. To display files use the pg (SV) or more (BSD) command. The cp command is designed specifically for copying files.

TYPICAL OPERATION

In this activity the cat command is used to display and create files using cat. Begin at the shell prompt.

1.  Type cat file1 and press Return. Notice that the contents of file1 are displayed to your screen.
2.  Type cat > file1 and press Return. The existing file1 is overwritten.
3.  Type the following text; press Return after each line. Press Ctrl-I and Ctrl-L in the text below; do not type "Ctrl-I" and "Ctrl-L." Press Ctrl-D to stop input to the cat command.
     cj> cat > file1
     This text is being read by cat from my terminal keyboard.
     Cat will read the text as it is typed and create file1.
     
     With a blank third line!
     ^I ^L Just a few control keys for demonstration.
     ^D
4.  Type cat -vte file1 (use -v -t -e on BSD systems) and press Return. Notice the $ (dollar signs) and the control characters (^I, ^L). The -vte option informs cat to display control characters in a readable format.
     cj> cat -vte file1
     This text is being read by cat from my terminal keyboard.$
     Cat will read the text as it is typed and create file1.$
     $
     With a blank third line!$
     ^I ^L Just a few control keys for demonstration.$
5.  Type cat file1 - file1 > file2 and press Return to make two copies of file1 in file2 with input from your keyboard placed in between the two copies.
a.  Now type ===== and press Return.
b.  Press Ctrl-D to end the keyboard input.
6.  Now display file2 by typing cat file2 and pressing Return. Your output should resemble the following display. Notice the five equal signs (=====) between the two files.
     cj> cat file2
     This text is being read by cat from my terminal keyboard.
     Cat will read the text as it is typed and create file1.
     
     With a blank third line!
          Just a few control keys for demonstration.
     =========
     This text is being read by cat from my terminal keyboard.
     Cat will read the text as it is typed and create file1.
     
     With a blank third line!
          Just a few control keys for demonstration.
7.  Type Is and press Return to display the files in your current directory. Your display should resemble the following:
     cj> ls
     bin  calendar db  file1    file2    letters   myfile
8.  Turn to Module 63 to continue the learning sequence.


Previous Table of Contents Next