gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:32:12 30 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Use tee (or equivalent) but limit max file size or rotate to new file

(7 个回答)


6年前关闭。




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

和输出文件 /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)

关于bash - 如何限制日志文件中的最大行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34609536/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com