如何限制日志文件中的最大行数

How to limit maximum line in log file

给定一个 bash 脚本 运行 ping -c 25 google.com | tee /home/user/myLogFile.log

输出文件/home/user/myLogFile.log包含:

PING google.com (117.102.117.238) 56(84) bytes of data. 
64 bytes from 117.102.117.238: icmp_seq=1 ttl=61 time=12.7 ms
64 bytes from 117.102.117.238: icmp_seq=2 ttl=61 time=61.1 ms
(...)
64 bytes from 117.102.117.238: icmp_seq=25 ttl=61 time=7.11 ms

--- google.com ping statistics ---
25 packets transmitted, 25 received, 0% packet loss, time 24038ms
rtt min/avg/max/mdev = 5.573/11.293/61.102/11.210 ms

如何限制日志文件中的最大行数,如果达到最大行数,将重置文件并保存下一个输出?

好的,我想你可以这样做:

ping -c 25 google.com | tee >(split -d -b 100000 - /home/user/myLogFile.log)