The UNIX cat command

Recommended for you: Get network issues from WhatsUp Gold. Not end users.


This command is not "cat" means, but the abbreviation of catenate. As the name suggests, is to string together.

For example: cat file1 file2

The file file1 and File2 together, and then output to the screen. Note, the output to the screen is a custom cat. If you want to change the direction of its output, output redirection must use the Unix operating system. " > " " > ", output redirection operator. A little bit high DOS users are aware of this symbol. In the Unix operating system in use is not a big difference with Dos. But in different places, Unix operating system will be a peripheral any agree to a file.

So if you want to redirect the output to the printer or something, just write on behalf of the printer device file name. The previous chapter we said terminal machine name, it is also a document.

For example, my equipment is ttya, and Li's equipment machine is ttyb, he want me to put the contents of the current directory to him. Use this command to the LS -a-u-F > ttyb. It makes full use of the design idea of Unix operating system multi-user system.

Use the same LS -a-u-F> file1 is the current Unix operating system directory list output to file1.

Another example: cat file1 file2>file3
The file file1 and the contents of the File2 output to file3. In Dos this command is written in copy file1+file2 file3

When you use'> 'time to redirect output, Unix operating system immediately opens an empty file for storing'>' before the file command output.

For example:
cat file1 file2>file3

The system first file3 emptied of its contents. So: cat file1 file2> file1 this command will generate an error. Perhaps this command is intended to increase the content of the file1, but when the initial system this command to the content of the file1 is empty. So you get an error message. If you want to add the contents of the file using the following command: cat file2> > file1, " > > " said that additional, rather than to empty the contents of the file1.

Unix commands commonly used cat command type parameters

  Command: cat

  Use: all users access

  Using way: cat [-AbeEnstTuv] [--help] [--version] fileName

  Note: the file on back to the basic output connection (screen or > fileName to another file)


  -n or --number from 1 to all output line numbers

  -b or --number-nonblank and -n, like but for the blank line is not numbered

  -s or --squeeze-blank when there is a blank line for two more lines, as substitution for a blank line

  -v or --show-nonprinting


  cat -n textfile1 > Textfile2 the file contents of textfile1 plus line after the input textfile2 in this file

  cat -b textfile1 textfile2 >> Textfile3 the file contents of textfile1 and textfile2 with line numbers (blank lines without) the content added to the textfile3

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Nikita at December 26, 2013 - 12:21 PM