Linux Command cat usage

Source: Internet
Author: User
Tags lstat

Do you know what Linux commands are? This very advanced application technology will be explained by me very much. Where is Linux Command NB? Next I will go into the unlimited field of Linux commands.

The Linux Command cat-concatenate files and print on the standard output connects the file and outputs it to the screen. In fact, it is to view the file content.
SYNOPSIScat [OPTION] [FILEDESCRIPTIONConcatenate FILE (s), or standard input, to standard output.
-A, show-allequivalent to-vET -- equivalent to parameter-vET
-B, number-nonblanknumber nonblank output lines -- Do not number blank rows, similar to-n.
-E, equivalent to-vE -- equivalent to the parameter-vE
-E, show-ends display $ at end of each line -- each line ends with a $ symbol.
-N, number all output lines -- number of all output rows starting from 1
-S, squeeze-blank never more than one single blank line -- When there are two or more blank rows in a row, only one row of blank rows is retained.
-T, equivalent to-vT
-T, show-tabsdisplay TAB characters as ^ I
-U, (ignored)
-V, show-nonprintinguse ^ and M-notation, struct t for LFD and TAB

Linux Command exercise:
[Root @ CentOS4 OK _008] # cat mytestHello world!
Hello world 1
Hello world 2
Hello world 3
[Root @ CentOS4 OK _008] # cat-n mytest
Hello world!
Hello world 1
Hello world 2
Hello world 3
[Root @ CentOS4 OK _008] # cat-B mytest
1 Hello world!
2 Hello world 1
3 Hello world 2
4 hello world 3 from the above Linux commands we can verify the difference between-n and-B.
[Root @ CentOS4 OK _008] # cat-B-E mytest
1 Hello world! $
2 Hello world 1 $
3 Hello world 2 $
4 hello world 3 $
Each line ends with a $ symbol.

Keys [root @ CentOS4 OK _008] # ls-ltotal 24-rw-r -- r -- 1 root 59 Sep 18 mytestdrwxr-xr-x 3 root 4096 Sep 13 OK-rw-r -- r -- 1 root 21 Sep 17 20:45 oktest [root @ CentOS4 OK _008] # cat mytest oktest> newtest.txt [root @ CentOS4 OK _008] # ls-ltotal 32-rw-r -- r -- 1 root 59 Sep 18 mytest-rw-r -- 1 root 80 Sep 18 newtest.txt drwxr-xr-x 3 root 4096 Sep 13 OK-rw-r -- 1 root 21 Sep 17 oktest.txt content of the new file newtest.txt: [root @ CentOS4 OK _008] # cat-B newtest.txt
1 Hello world!
2 Hello world 1
3 Hello world 2
4 hello world 3
5 this is a test file.

Merge the content of the two files [root @ CentOS4 OK _008] # cat mytest oktest> newtest1.txt [root @ CentOS4 OK _008] # ls-ltotal 40
-Rw-r -- 1 root 59 Sep 18 :48 mytest
-Rw-r -- 1 root 80 Sep 18 :56 newtest1.txt
-Rw-r -- 1 root 80 Sep 18 :53 newtest.txt
Drwxr-xr-x 3 root 4096 Sep 13 OK
-Rw-r -- 1 root 21 Sep 17 20:45 oktest

[Root @ CentOS4 OK _008] # cat-B newtest1.txt
1 Hello world!
2 Hello world 1
3 Hello world 2
4 hello world 3
5 this is a test file.

We will find that the results returned by cat mytest oktest> newtest1.txt and cat mytest oktest> newtest.txt are the same here. In fact, according to the example of the complete set of common Linux commands: cat-n textfile1> textfile2 Add the textfile1 file content to the row number and enter textfile2 in the file cat-B textfile1 textfile2> textfile3 Add the textfile1 and textfile2 file content to the blank row of the row number without adding) later, we can see the differences between the two Linux commands. Here we will not write more examples.

Run the Linux Command to clear the content of a file:
[Root @ CentOS4 OK _008] # cat/dev/null> mytest
[Root @ CentOS4 OK _008] # cat-B mytest
[Root @ CentOS4 OK _008] # ls-l
Total 52
-Rw-r -- 1 root 0 Sep 18 20:05 mytest
-Rw-r -- 1 root 80 Sep 18 :56 newtest1.txt
-Rw-r -- 1 root 93 Sep 18 20:01 newtest3.txt
-Rw-r -- 1 root 93 Sep 18 20:01 newtest4.txt
-Rw-r -- 1 root 80 Sep 18 19:53 newtest.txt
Drwxr-xr-x 3 root 4096 Sep 13 OK
-Rw-r -- 1 root 34 Sep 18 20:00 oktest
-- Tomorrow I will find out why cat/dev/null> mytest can be used to clear the file content.

Run the Linux Command to create a new file:
[Root @ CentOS4 OK _008] # cat> new.txt -- press CTRL + C to end the input.
[Root @ CentOS4 OK _008] # ls-l
Total 56
-Rw-r -- 1 root 0 Sep 18 20:05 mytest
-Rw-r -- 1 root 80 Sep 18 19:56 newtest1.txt
-Rw-r -- 1 root 93 Sep 18 20:01 newtest3.txt
-Rw-r -- 1 root 93 Sep 18 20:01 newtest4.txt
-Rw-r -- 1 root 80 Sep 18 :53 newtest.txt
-Rw-r -- 1 root 0 Sep 18 :07 new.txt
Drwxr-xr-x 3 root 4096 Sep 13 OK
-Rw-r -- 1 root 34 Sep 18 20:00 oktest
Run the preceding rmLinux command to delete some newly created files (such as newtest1.txt, newtest3.txt, newtest4.txt, newtest.txt, and new.txt:

[Root @ CentOS4 OK _008] # rm newtest1.txt newttest3.txt newtest4.txt newtest.txt
Rm: remove regular file 'newtest1.txt '? Y
Rm: cannot lstat 'newttest3.txt ': No such file or directory
Rm: remove regular file 'newtest4.txt '? Y
Rm: remove regular file 'newtest.txt '? Y
[Root @ CentOS4 OK _008] # rm newtest3.txt
Rm: remove regular file 'newtest3.txt '? Y
[Root @ CentOS4 OK _008] # ls-l
Total 24
-Rw-r -- 1 root 0 Sep 18 20:05 mytest
-Rw-r -- 1 root 0 Sep 18 :07 new.txt
Drwxr-xr-x 3 root 4096 Sep 13 OK
-Rw-r -- 1 root 34 Sep 18 20:00 oktest
[Root @ CentOS4 OK _008] # rm newt.txt
Rm: cannot lstat 'newt.txt ': No such file or directory
[Root @ CentOS4 OK _008] # rm new.txt
Rm: remove regular empty file 'new.txt '? Y
[Root @ CentOS4 OK _008] # ls-l
Total 20
-Rw-r -- 1 root 0 Sep 18 20:05 mytest
Drwxr-xr-x 3 root 4096 Sep 13 OK
-Rw-r -- 1 root 34 Sep 18 20:00 oktest
I learned this today and have a rest.
The preceding section describes the Linux Command application.

  1. Some Efficient Linux Command Line operations
  2. Cainiao notes: Linux commands
  3. Command Introduction: Basic Linux commands for file and directory management
  4. Learn about cat and learn Linux commands
  5. Brief Introduction to Linux Command output and command replacement

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.