View the tomcat run log in real time under linux

  • 2020-05-14 05:44:49
  • OfStack

1. First switch to: cd usr/local/tomcat5/logs

2, tail-f catalina.out

3. This allows the runtime to view the running logs in real time

Ctrl+c is the exit tail command.

By the way, the tail command in Linux

The tail command 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 part of the filename on the screen and refresh it so that you can see the latest file content.

1. Command format;

tail[necessary parameters][select parameters][file]

2. Command functions:

Used to display the end of a specified file and to process it as input when no file is specified. Log files are often viewed.

3. Command parameters:

-f loop read
-q does not display processing information
-v displays detailed processing information
-c < The number of > Number of bytes displayed
-n < The number of rows > According to the number of rows
--pid=PID combined with -f to indicate that the process ends after ID,PID dies.
-q, --quiet, --silent never outputs the header of a given file name
-s, -- sleep-interval =S combined with -f to indicate that S sleeps for a second at intervals between each iteration

4. Examples of use:

Example 1: displays the end of the file

Command:

tail -n 5 log2014.log

Output:


[root@localhost test]# tail -n 5 log2014.log 
2014-09
2014-10
2014-11
2014-12
==============================[root@localhost test]#

Description:

Displays the last five lines of the file

Example 2: loop through the file contents

Command:

tail -f test.log

Output:


[root@localhost ~]# ping 192.168.120.204 > test.log &
[1] 11891[root@localhost ~]# tail -f test.log 
PING 192.168.120.204 (192.168.120.204) 56(84) bytes of data.
64 bytes from 192.168.120.204: icmp_seq=1 ttl=64 time=0.038 ms
64 bytes from 192.168.120.204: icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from 192.168.120.204: icmp_seq=3 ttl=64 time=0.033 ms
64 bytes from 192.168.120.204: icmp_seq=4 ttl=64 time=0.027 ms
64 bytes from 192.168.120.204: icmp_seq=5 ttl=64 time=0.032 ms
64 bytes from 192.168.120.204: icmp_seq=6 ttl=64 time=0.026 ms
64 bytes from 192.168.120.204: icmp_seq=7 ttl=64 time=0.030 ms
64 bytes from 192.168.120.204: icmp_seq=8 ttl=64 time=0.029 ms
64 bytes from 192.168.120.204: icmp_seq=9 ttl=64 time=0.044 ms
64 bytes from 192.168.120.204: icmp_seq=10 ttl=64 time=0.033 ms
64 bytes from 192.168.120.204: icmp_seq=11 ttl=64 time=0.027 ms
[root@localhost ~]#

Description:

ping 192.168.120.204 > test. log & // in the background ping remote host. And output the file to test.log; This practice is also used for more than one file monitoring. Terminate with Ctrl+c.

Example 3: displays the file starting at line 5

Command:

tail -n +5 log2014.log

Output:


[root@localhost test]# cat log2014.log 
2014-01
2014-02
2014-03
2014-04
2014-05
2014-06
2014-07
2014-08
2014-09
2014-10
2014-11
2014-12
==============================
[root@localhost test]# tail -n +5 log2014.log
2014-05
2014-06
2014-07
2014-08
2014-09
2014-10
2014-11
2014-12
==============================

Related articles: