[Linux] command tail, cat, tac, head, and echo for viewing log files in linux,

Source: Internet
Author: User

[Linux] command tail, cat, tac, head, and echo for viewing log files in linux,

Linux Command for viewing Log File Content: tail, cat, tac, head, echo

Tail-f test. log
You will see that the screen is constantly printed. At this time, the first process is interrupted Ctrl-C,

---------------------------
How does one display certain lines of a file in linux (several lines in the middle)

The number of rows starts from 3,000th. Display 3000 ~ 3999 rows
Cat filename | tail-n + 3000 | head-n 1000

Display rows 1000 to 3000
Cat filename | head-n 3000 | tail-n plus 1000

* Pay attention to the order of the two methods
Decomposition:
Tail-n 1000: displays the last 1000 rows
Tail-n + 1000: The value ranges from 1000 rows to 1000 rows.
Head-n 1000: displays the first 1000 rows

Use sed command
Sed-n'5, 10p' filename so that you can view only rows 5th to 10th of the file.

Example: cat mylog. log | tail-n 1000 # output the last one thousand lines of mylog. log File

---------------------------
Cat has three main functions:
1. display the entire file at a time. $ Cat filename
2. Create a file from the keyboard. $ Cat> filename
Only new files can be created, and existing files cannot be edited.
3. Merge several files into one file: $ cat file1 file2> file
Parameters:
-N or -- number indicates the number of all output rows starting from 1.
-B or -- number-nonblank is similar to-n, but is not numbered for blank rows.
-S or -- squeeze-blank when there are two consecutive blank rows or more, it is replaced by a blank row
-V or -- show-nonprinting
Example:
Add the row number to the file content of textfile1 and enter textfile2.
Cat-n textfile1> textfile2

Add the row number to the file content of textfile1 and textfile2 (blank rows are not added) and then append the content to textfile3.
Cat-B textfile1 textfile2> textfile3

Throw the test.txt file into the garbage box and leave the value test.txt empty.
Cat/dev/null>/etc/test.txt
Note:> Create,> append. Never confuse.
------------------------------------------
Tac (reverse list)
Tac reversed cat, so its function is opposite to cat. cat is displayed continuously on the screen from the first row to the last row,
Tac is displayed on the screen from the last line to the first line!

------------------------------------------
In Linux, the echo command is used to display a section of Characters in the standard output, for example:
Echo "the echo command test! "

This will output "the echo command test !" This line of text!

Echo "the echo command test! "> A. sh
This will output "the echo command test!" in the. sh file !" This line of text!
The general format of this command is echo [-n] string, where option n indicates that the output text is not wrapped after the line break; the string can be enclosed by quotation marks or without quotation marks.
When you use the echo command to output a string with quotation marks, the string is output as is;
When a string without quotation marks is output using the echo command, each word in the string is output as a string, and each string is separated by a space.

Source: https://www.cnblogs.com/zdz8207/p/linux-log-tail-cat-tac.html

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.