Basic commands for viewing logs in linux and linux

Source: Internet
Author: User

Basic commands for viewing logs in linux and linux
1. cat command:

Function:1) display the entire file.

Example: $ cat fileName

2) connect the file string to the Basic output, for example, merge several files into one file or output them to the screen.

Example: $ cat file1 file2> file

Note: connect the archive string and upload it to the Basic output (screen or add> fileName to another archive)
Cat parameters:
-N or-number indicates the number of all output rows starting from 1.
-B or-number-nonblank is similar to-n, except that the blank row is not numbered.
-S or-squeeze-blank when there are two consecutive blank rows or more, it is replaced by a blank row
-V or-show-nonprinting

2. more command:

View logs as a percentage.

 

3. less command:

Similar to the more function, but less supports reading files before and after.

 

4. head command:

Function:The head command is used to view the beginning of a text file.

Example:
Head example.txt displays the top 10 lines of example.txt;
Head-n 20 example.txt displays the first 20 rows of content in the file example.txt;
Head details:
-N specifies the number of lines of text to be displayed.
The-n number parameter must be a decimal integer, which determines the position in the file, in the unit of action.
The-c number Parameter 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 last few lines of a text file.

Example:

Tail example.txt displays the last 10 lines of example.txt;
Tail-n 20 example.txt displays the last 20 lines of content in the file example.txt;
Tail-f example.txt displays the last 10 lines of example.txt file. After the file content is added, the new file content is automatically displayed.

Tail-n 50-f example.txt displays the last 50 lines of example.txt file. After the file content is added, the new file content is automatically displayed.
Note:
The last command is very useful, especially when monitoring log files, you can always display new log information on the screen.

Tail details:
-B Number reads the specified file from the location of the 512-byte block indicated by the Number variable.
-C Number reads the specified file from the byte location indicated by the Number variable.
-F if the input File is a regular File or if the File parameter specifies FIFO (first-in-first-out ),
The tail command will not terminate after the last specified unit of the input file is copied, but will continue
Read and copy additional units from the input file (when these units are available ). If the File parameter is not specified,
If the standard input is a pipe, the-f flag is ignored. The tail-f command can be used to monitor the growth of files being written by another process.
-K Number reads the specified file from the 1KB block location indicated by the Number variable.
-M Number reads the specified file from the Multi-byte character position indicated by the Number variable. Use this flag to provide consistent results in the single-byte and double-byte character code set environments.
-N Number reads the specified file from the first or last row. The position is indicated by the Number variable symbol (+ or-or none) and is displaced by the Number of the row.
-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, the-r flag only displays the last 20,480 bytes. -R flag only
It is valid only when it is used together with the-n mark. Otherwise, it will be ignored.


Command for viewing linux system logs

Take a look:
Linux.vbird.org/linux_basic/0570syslog.php
Www.ibm.com/..x.html

In Linux, what are the common commands used to view log files?

All of them are under/var/log.

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.