Cat usage summary and cat usage Summary

Source: Internet
Author: User

Cat usage summary and cat usage Summary

 

1. view files
In LINUX, everything is a file. It is not enough for us to see the file name and directory name. Today, we will introduce the command cat for opening files. Of course, cat cannot be used for binary executable files.
In CentOS7, the/etc/profile file is used as an example, as follows:

First, how can I open this file? Run: cat/etc/passwd.

Can we see the row number for so many rows?
Cat-n/etc/passwd
-N: number

Obviously, empty rows are also marked in order. So how can we not Mark empty rows but only rows with content?
Cat-B/etc/profile
-B: number-nonblank

If multiple rows are empty, can they be compressed into one empty row?
Cat-sb/etc/profile
-S: squeeze-blank

However, the cat command cannot eliminate all blank lines.
Some unprintable characters are not displayed in the cat command. If you need to know, the displayed command is as follows:
Cat-An/etc/profile
-A: show-all is equivalent to-vET.
-E, -- show-ends: $ is displayed at the end of each line, and a line break is displayed.
-T, -- show-tabs: The jump character is displayed as ^ I

Common cat options for viewing files are:
Cat-nAb/etc/profile

2. Create a file
Cat can view the file content or create a file.
For example, create an aaa.txt file with the following content:
Cat> aaa.txt <EOF
> This is txt
>
> Sucess
> EOF

The Aaa.txt file has been created and can be viewed as follows:
Input: cat aaa.txt

If aaa.txt already exists, you need to append the content to this file, instead of overwriting the original content of the file. Use cat> aaa.txt <EOF
> Where is not first line
>
> Yes
> Sucess
> EOF

Explanation: After cat,> (Append content to the file, the original file exists) or> (create a new file). EOF can also be changed to other uppercase letters, but must correspond to each other.
3. Merge files
What should I do if I want to put two files into one?
For example, the above/etc/profileand aaa.txt files are displayed on the screen:
Cat aaa.txt/etc/profile

Therefore, you can use redirection to output the two files to a new file.
Cat aaa.txt/etc/profile> bbb.txt
Cat bbb.txt

 


 

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.