In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How do I use the tail command to view log files in linux? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
1. Command format
Tail [necessary parameters] [Select parameters] [File]
2. Command function:
Used to display the end of the specified file, and when no file is specified, it is processed as input information. Commonly used to view log files.
-f loop read
-Q does not display processing information
-v displays detailed processing information
Number of bytes displayed by-c
-n shows the number of rows
-- pid=PID is used with-f to indicate that it ends after the process ID,PID dies.
-Q,-- quiet,-- silent never outputs the first part of the given file name
-s,-- sleep-interval=S is used with-f to indicate dormancy for S seconds at intervals of each iteration.
4. Use an example:
Example 1: displays the content at the end of the file
Command:
Tail-n 5 / var/log/yum.log
Output:
[root@linux linux] # tail-n 5 / var/log/yum.logJun 29 14:45:30 Installed: samba-3.6.23-35.el6_8.i686Jun 29 14:45:31 Installed: 2:xinetd-2.3.14-40.el6.i686Jun 29 14:45:34 Installed: samba-swat-3.6.23-35.el6_8.i686Jun 29 14:45:37 Updated: samba-client-3.6.23-35.el6_8.i686Jun 29 14:45: 37 Updated: libsmbclient-3.6.23-35.el68.i686 [root @ linux linux] #
Description:
Show the last five lines of the file
Example 2: loop through the contents of the file
Command:
Tail-f / var/log/yum.log
Output:
Jun 22 19:54:08 Updated: PackageKit-device-rebind-0.5.8-26.el6.i686Jun 22 19:54:09 Updated: rpm-build-4.8.0-55.el6.i686Jun 29 14:45:24 Updated: samba-winbind-3.6.23-35.el6_8.i686Jun 29 14:45:24 Updated: samba-winbind-clients-3.6.23-35.el6_8.i686Jun 29 14:45:28 Updated: samba-common-3.6.23-35 .el6 _ 8.i686Jun 29 14:45:30 Installed: samba-3.6.23-35.el6_8.i686Jun 29 14:45:31 Installed: 2:xinetd-2.3.14-40.el6.i686Jun 29 14:45:34 Installed: samba-swat-3.6.23-35.el6_8.i686Jun 29 14:45:37 Updated: samba-client-3.6.23-35.el6_8.i686Jun 29 14:45:37 Updated: libsmbclient-3.6.23-35.el6_8.i686
This command can view the log in real time, and automatically refresh the log, so that we can see the latest log file, know the execution process of our program, and facilitate the search of problems.
Supplement
Use
Writes the file to standard output from the specified point. Using the-f option of the tail command, you can easily view the changing log file. Tail-f filename will display the last content of the filename on the screen and not only refresh it, so that you can see the latest file contents.
Grammar
Standard grammar
Tail [- f] [- c Number |-n Number |-m Number |-b Number |-k Number] [File]
To display rows in reverse order
Tail [- r] [- n Number] [File]
Description
The tail command writes the file specified by the File parameter to standard output from the specified point. If no file is specified, standard input is used. The Number variable specifies how many cells are written to standard output. The value of the Number variable can be a positive or negative integer. If the value is preceded by a + (plus sign), the file is written to standard output starting with the number of cells specified at the beginning of the file. If the value is preceded by a-(minus sign), the file is written to standard output starting with the number of cells specified at the end of the file. If the value is not preceded by a + (plus sign) or-(minus sign), the file is read from the unit number specified at the end of the file.
The type of unit used by the Number variable to determine the starting point of the count is determined by the-b,-c,-k,-m, and-n flags. If no one of these flags is specified, the tail command reads the last ten lines of the specified file and writes it to standard output. This is the same as typing-n 10 on the command line.
The-m flag provides consistent results in single-byte and double-byte character environments. The-c flag should be used with caution when the input is a text file that contains multi-byte characters, as the resulting output may not start at the character boundary.
Mark
-b Number
Reads the specified file from the 512-byte block location represented by the Number variable.
-c Number
Reads the specified file from the byte position represented by the Number variable.
-f
If the input file is a regular file or if the File parameter specifies FIFO, the tail command does not terminate after copying the last specified unit of the input file, but continues to read and copy additional units from the input file (when those units are available). If no File parameter is specified 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 being written by another process.
-k Number
Reads the specified file from the location of the 1KB block represented by the Number variable.
-m Number
Reads the specified file starting from the multibyte character position represented by the Number variable. Use this flag to provide consistent results in single-byte and double-byte character code set environments.
-n Number
Reads the specified file starting at the line location represented by the Number variable.
-r
Displays the output in reverse order from the end of the file. The default value of the-r flag is to print the entire file in reverse order. If the file is larger than 20480 bytes, the-r flag displays only the last 20480 bytes.
The-r flag is valid only with the-n flag. Otherwise, it will be ignored.
Exit statu
The command returns the following exit values:
0
Completed successfully.
0
An error has occurred.
Example
To display the last ten lines of the notes file, type:
Tail notes to specify the number of lines to read from the end of the notes file, enter:
Tail-n 20 notes
To start with byte 200, display the notes file one page at a time, enter:
Tail-c + 200notes | pg
To track the growth of the file, enter:
Tail-f accounts
What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.
After reading the above, do you know how to use the tail command to view log files in linux? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.