Linux View log file Contents command tail, Cat, TAC, head, Echo

Source: Internet
Author: User
Tags echo command

Linux View log file Contents command tail, Cat, TAC, head, Echo

Tail-f Test.log
You will see that the screen is constantly being printed out. This time interrupts the first process ctrl-c,

---------------------------
How Linux displays a few lines of a file (in the middle of a few lines)

Starting at line No. 3000, displays 1000 rows. The 3000~3999 line is displayed
Cat FileName | Tail-n +3000 | Head-n 1000

Display 1000 rows to 3000 rows
Cat filename| Head-n 3000 | Tail-n +1000

* Note the order of the two methods
Decomposition:
Tail-n 1000: Show last 1000 rows
Tail-n + 1000: Starting from 1000 lines, showing 1000 rows later
Head-n 1000: Show front 1000 lines

Command with SED
Sed-n ' 5,10p ' filename so you can only view lines 5th through 10th of the file.

Example: Cat MyLog.log | Tail-n #输出mylog. log file last 1000 lines

---------------------------
There are three major features of cat:
1. Display the entire file at once. $ 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 the number of rows for all outputs starting from 1
-B or--number-nonblank and-n similar, except for blank lines not numbered
-S or--squeeze-blank when you encounter a blank line that has more than two consecutive lines, replace the blank line with one line
-V or--show-nonprinting
Cases:
Add a line number to the Textfile1 file and enter the Textfile2 file.
Cat-n textfile1 > Textfile2

Append the contents of the Textfile1 and Textfile2 files to the textfile3 after adding the line number (blank line not added).
Cat-b textfile1 textfile2 >> textfile3

Throw the Test.txt file into the trash, and assign a null value Test.txt
Cat/dev/null >/etc/test.txt
Note:> means that the creation of,>> is appended. Don't get mixed up.
------------------------------------------
TAC (Reverse list)
The TAC is writing cat back, so his function is the opposite of cat, and cat is continuously displayed on the screen from the first line to the last line,
The TAC is then shown on the screen by the last line to the first line in reverse!

------------------------------------------
The echo command in Linux is used to display a section of characters on the standard output, such as:
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 a.sh file. This line of text!
The general format of the command is: Echo [-n] string where option n means that the output text is not wrapped, the string can be quoted, or it can be unquoted.
When you output a quoted string with the Echo command, the string is output as it is;
When you output an unquoted string with the echo command, each word in the string is output as a string, separated by a space between the strings.

Linux View log file Contents command tail, Cat, TAC, head, Echo

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.