Like what you see? Get it in one document for easy printing!
Click Here!

Custom Search







Table Of Contents  CertiGuide to A+ (A+ 4 Real)
 9  Chapter 5: The Linux Operating System
      9  Basic Concepts and Procedures for Creating, Viewing and Editing Files and Directories
           9  Common Commands

Previous Topic/Section
touch - Change File Time Stamps
Previous Page
Pages in Current Topic/Section
1
Next Page
more, less - Peruse A File One Screen at a Time
Next Topic/Section

cat - Concatenate Files And Print To The Standard Output

The cat command has three important uses, it can be used to display short files to the screen, append files together and output them to a third file, or it can be used to input text from the keyboard to a file. To display a short file to the screen use:

cat file_name

This will copy the file, file_name, to the standard output which is the screen.

The file command which will discussed later will identify non-ASCII files before they are viewed.

To enter small amounts of data into a file the cat command to be used in the following form:

cat > file

This will cause whatever is entered on the keyboard to be displayed on the screen and simultaneously written to the file and will continue until the control key and the D key are pressed (^D) to send an end-of -file and terminate the process. This is an easy way to quickly enter small amounts of data into a file, however it is not possible to edit this data using cat, editing can be done with the vi editor, which will be discussed later in this section. When one needs to create a file and enter a small amount of data, this command can be more convenient than starting an editor to enter the data.

The third form of the command is:

cat file_1 file_2 > file_3

This will initially wipe out any contents of file_3 if it exists or create it if it does not and copy the contents of file_1 to file_3 and then append the contents of file_2 to file_3. The net result after this command executes is that file_3 will contain the contents of file_1 followed by the contents of file_2.

The form:

cat file_1 file_2 >> file_3

will append the contents of file_1 to the end of file_3 then append the contents of file_2 to the end of the new file_3. Now file_3 will contain its original contents, followed by the contents of file_1 then followed by the contents of file_2. It is important to remember the distinction between these two commands. If file three has contents, the first form will initially delete those contents before the command executes. Care must be taken to avoid inadvertently destroying the contents of an existing file.


Previous Topic/Section
touch - Change File Time Stamps
Previous Page
Pages in Current Topic/Section
1
Next Page
more, less - Peruse A File One Screen at a Time
Next Topic/Section

If you find CertiGuide.com useful, please consider making a small Paypal donation to help the site, using one of the buttons below. You can also donate a custom amount using the far right button (not less than $1 please, or PayPal gets most/all of your money!) In lieu of a larger donation, you may wish to consider buying an inexpensive PDF equivalent of the CertiGuide to A+ (A+ 4 Real) from StudyExam4Less.com. Thanks for your support!
Donate $2
Donate $5
Donate $10
Donate $20
Donate $30
Donate: $



Home - Table Of Contents - Contact Us

CertiGuide to A+ (A+ 4 Real) (http://www.CertiGuide.com/apfr/) on CertiGuide.com
Version 1.0 - Version Date: March 29, 2005

Adapted with permission from a work created by Tcat Houser et al.
CertiGuide.com Version Copyright 2005 Charles M. Kozierok. All Rights Reserved.
Not responsible for any loss resulting from the use of this site.