Linux basic operations on file content (study note 7), linux Study Notes

Source: Internet
Author: User

Linux basic operations on file content (study note 7), linux Study Notes
I. cat1.1. view the File Content

Format: cat file name

[root@model /]# cat /etc/resolv.conf # Generated by NetworkManagernameserver 10.198.1.1nameserver 8.8.8.8[root@model /]# 

However, when the file content is large and more than one screen is displayed, the cat command cannot meet the viewing requirements. more | less is required for viewing.

1.2 redirect the content of the input file to the new file
[root@model Documents]# cat /etc/resolv.conf  > a.txt[root@model Documents]# cat a.txt # Generated by NetworkManagernameserver 10.198.1.1nameserver 8.8.8.8[root@model Documents]# 

">" Indicates clearing the file and writing new content again. If the file exists, it is cleared. If the file does not exist, it is created.

Two ">" indicates the end of The append at the end of the file. If the file exists, it is added. If the file does not exist, it is created.

[root@model Documents]# cat /etc/httpd/conf.d/welcome.conf >>a.txt[root@model Documents]# cat a.txt # Generated by NetworkManagernameserver 10.198.1.1nameserver 8.8.8.8# # This configuration file enables the default "Welcome"# page if there is no default index page present for# the root URL.  To disable the Welcome page, comment# out all the lines below.#<LocationMatch "^/+$">    Options -Indexes    ErrorDocument 403 /error/noindex.html</LocationMatch>[root@model Documents]# 
1.3. Clear or append the redirected File
[root@model Documents]# cat > a.txt<<gg> hello linux> gg[root@model Documents]# cat a.txt hello linux[root@model Documents]# 
[root@model Documents]# cat >> a.txt <<fw> rrrrrrrrrrrrrr> qqqqqqqqq> wwwwwwwwwww> eeeeee> fw[root@model Documents]# cat a.txt hello linuxrrrrrrrrrrrrrrqqqqqqqqqwwwwwwwwwwweeeeee[root@model Documents]# 

Write the meat between two identifiers into the file. The two identifiers can be customized and appear in pairs.

">" Indicates clearing the file and writing new content again. If the file exists, it is cleared. If the file does not exist, it is created.

Two ">" indicates the end of The append at the end of the file. If the file exists, it is added. If the file does not exist, it is created.

2. more/less

Format: more/less file name

Used to view the file content when the file content is large: Press ENTER or space to flip the page down, press B to flip the page up, and press q to exit

The cat paging function is often used with the more command. The cat command also combines several files into one file.
More command: Pause the screen when the page is full. Press space to continue displaying the next screen or press the Q key to stop the screen.
Less command: the usage of the less command is similar to that of the more command. It can also be used to browse files on more than one page. The difference is that the less command can not only display the file down by pressing the Space key, but also use the up or down key to scroll the file. To end browsing, press the Q key at the less command prompt.
In fact, apart from the cat command, these three commands have the ability to merge files. The other functions are similar, but they differ in browsing habits and display methods.

Iii. grep

Is a powerful text search tool that uses regular expressions to search for text and print matching rows.

[root@model Documents]# grep -i "q" a.txt qqqqqqqqq[root@model Documents]# grep -iv "q" a.txt hello linuxrrrrrrrrrrrrrrwwwwwwwwwwweeeeee[root@model Documents]# 
Iv. vi

Simple command:

Simple application:

Vi file name

Press I to edit

Press ESC, q to exit and do not save

Press ESC,: q! Exit and do not save

Press ESC,: wq to exit and save

 

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.