Linux View Log commands

Source: Internet
Author: User

1. Cat command:

function:1) Displays the entire file.

Example: $ cat FileName

2) Connect the file string to the basic output, such as merging several files into one file or output to the screen.

Example: $ cat file1 file2 > file

Description: Connect the file string to the basic output (screen or add > FileName to another file)
Detailed Cat 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

2. More Commands:

View the log as a percentage.

3. Less command:

Similar to more features, but less support to scroll through the file.

4. Head command:

function: from the beginning of the text file, the Head command is used to view the beginning of a text file.

Examples are as follows:
Head Example.txt Displays the first 10 lines of the file example.txt;
Head-n Example.txt Display the first 20 lines of the file example.txt;
Head Detail:
-n Specifies how many lines of text you want to display.
-N Number This parameter option must be a decimal integer and it will determine the position in the file in the behavior unit.
-C Number This parameter option must be a decimal integer, which determines the position in the file, in bytes.

5. Tail Command:

function:the tail command is used to display the end lines of a text file.

Examples are as follows:

Tail Example.txt Display the following 10 lines of the file example.txt;
Tail-n example.txt Display the file example.txt the following 20 lines of content;
Tail-f Example.txt Displays the following 10 lines of the file Example.txt and automatically displays the contents of the new file after the contents of the file have been increased.

Tail-n 50-f Example.txt Displays the following 50 lines of the file Example.txt and automatically displays the contents of the new file after the contents of the file have been increased.
Attention:
The last command is useful, especially when you are monitoring log files, and you can always display new log information on the screen.

Tail Detailed:
-B number starts reading the specified file from the 512-byte block position represented by the number variable.
-c number reads the specified file starting at the byte position represented by the number variable.
-F If the input file is a regular file or if the filename parameter specifies a FIFO (first in, out),
Then the tail command will not terminate after the last specified unit of the input file has been copied, but continue
Read and copy additional units from the input file (when these units are available). If you do not specify a File parameter,
And the standard input is a pipe, the-f flag is ignored. The tail-f command can be used to monitor the growth of files that another process is writing.
-K number reads the specified file starting at the 1KB block position represented by the number variable.
-m number starts reading the specified file from the multibyte character position represented by the # variable. Use this flag to provide consistent results in a single-byte and double-byte character code set environment.
-N number reads the specified file from the first or last row position, represented by the sign of the number variable (+ or-or none), and is shifted by the Line No.
-R Displays the output in reverse order from the end of the file. The default value of the-R flag is to display the entire file in reverse order. If the file is larger than 20,480 bytes, then the-r flag displays only the last 20,480 bytes. -R Flag only
is valid with the-n flag. Otherwise, it will be ignored.

Linux View Log commands

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.