Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the use of tail Command in Linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article analyzes "how to implement the use of tail commands in Linux". The content is detailed and easy to understand. Friends who are interested in "how to achieve the use of tail commands in Linux" can follow the editor's train of thought to read it in depth. I hope it will be helpful to you after reading. Let's learn more about "how to use tail commands in Linux" with the editor.

The tail command prints the last 10 lines of each file to standard output. For multiple files, precede each file with a header that gives the file name. If there is no file, or if the file is -, the standard input is read. Use the tail command to view the yum.log log file and display the last 10 lines. By default, tail displays the last 10 lines of your asking price:

How to use the tail command

[root@localhost] # tail / var/log/yum.logMay 26 15:22:08 Installed: pytalloc-2.1.16-1.el7.x86_64May 26 15:22:08 Updated: libwbclient-4.10.4-11.el7_8.x86_64May 26 15:22:08 Installed: samba-libs-4.10.4-11.el7_8.x86_64May 26 15:22:08 Updated: samba-common-libs-4.10.4-11.el7_8.x86_64May 26 15:22:08 Updated: samba-client-libs-4.10.4-11.el7_8.x86_64May 26 15:22:08 Updated: libsmbclient-4.10.4-11.el7_8.x86_64May 26 15:22:08 Installed: libarchive-3.1.2-14.el7_7.x86_64May 26 15:22:09 Installed: samba-client-4.10.4-11.el7_8.x86_64May 26 17:22:44 Installed: lm_sensors-libs- 3.4.0-8.20160601gitf9185e5.el7.x86_64May 26 17:22:44 Installed: sysstat-10.1.5-19.el7.x86_64

How to display the specified number of rows

Use the-n command to display the specified number of lines, or you can omit the letter n and use only-and numbers (there is no space between the numbers and -).

For example: view the user you created, and view the last two lines of the / etc/passwd file:

[root@localhost] # tail-2 / etc/passwdbob:x:1000:1001::/home/bob:/bin/bashuser01:x:1001:1002::/home/user01:/bin/bash

How to monitor file changes in real time

If you need to monitor changes to the contents of the file, use the-f option. This option is useful for monitoring log files. For example, to display the last 10 lines of the / var/log/nginx/error.log file and monitor for updates to the file:

[root@localhost] # tail-f / var/log/messages

To exit, press Ctrl+C to exit.

View multiple files

If multiple files are provided as input to the tail command, it displays the last ten lines of each file. The following example uses the tail command to display the last two lines of the / etc/passwd and / etc/shadow files:

[root@localhost ~] # tail-n 2 / etc/passwd / etc/shadow== > / etc/passwd / etc/shadow

The tail command is used with other commands

For example, to monitor the apache access log file in real time and display the line containing the IP address 192.168.43.157, you can use:

[root@localhost] # tail-f / var/log/httpd/access_log | grep 192.168.43.157192.168.43.157-- [28/May/2020:14:56:31 + 0800] "GET / HTTP/1.1" 403 4897 "-" curl/7.29.0 "192.168.43.157-- [28/May/2020:14:56:41 + 0800]" GET / HTTP/1.1 "403 4897"-"curl" / 7.29.0 "192.168.43.157-- [28/May/2020:14:56:41 + 0800]" GET / HTTP/1.1 "403 4897"-"curl/7.29.0" 192.168.43.157-[28/May/2020:14:56:41 + 0800] "GET / HTTP/1.1" 403 4897 "-"curl/7.29.0"

The tail command prints the last 10 lines of each file to standard output. For multiple files, precede each file with a header that gives the file name.

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.

On how to achieve the use of tail commands in Linux to share here, I hope that the above content can make you improve. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report