linux cat /dev/null > 日志文件 方法清空日志文件并保持文件可继续写入,无需重启写入进程,适用于nginx,docker等日志清空
测试程序javastatic void fileout() throws IOException, InterruptedException {FileOutputStream fileOutputStream = new FileOutputStream("/tmp/a.out");for(int i = 0;i<1000;i++){fileOutputStream.write((Syst
·
测试程序java
static void fileout() throws IOException, InterruptedException {
FileOutputStream fileOutputStream = new FileOutputStream("/tmp/a.out");
for(int i = 0;i<1000;i++){
fileOutputStream.write((System.currentTimeMillis()+"").getBytes(StandardCharsets.UTF_8));
Thread.sleep(500);
}
fileOutputStream.close();
}
清空测试
yeqiang@yeqiang-PC:~$ cat /dev/null > /tmp/a.out
yeqiang@yeqiang-PC:~$ cat /dev/null > /tmp/a.out
yeqiang@yeqiang-PC:~$ cat /dev/null > /tmp/a.out
yeqiang@yeqiang-PC:~$ cat /dev/null > /tmp/a.out
yeqiang@yeqiang-PC:~$ cat /dev/null > /tmp/a.out
yeqiang@yeqiang-PC:~$ cat /dev/null > /tmp/a.out
yeqiang@yeqiang-PC:~$ cat /dev/null > /tmp/a.out
yeqiang@yeqiang-PC:~$ cat /dev/null > /tmp/a.out
yeqiang@yeqiang-PC:~$ cat /dev/null > /tmp/a.out
yeqiang@yeqiang-PC:~$ cat /dev/null > /tmp/a.out
yeqiang@yeqiang-PC:~$ cat /dev/null > /tmp/a.out
yeqiang@yeqiang-PC:~$ cat /dev/null > /tmp/a.out
yeqiang@yeqiang-PC:~$ cat /dev/null > /tmp/a.out
tail效果
yeqiang@yeqiang-PC:~$ tail -f /tmp/a.out
1642727380983164272738148316427273819831642727382483164272738298416427273834841642727383984164272738448416427273849841642727385484164272738598416427273864851642727386985164272738748516427273879851642727388485164272738898516427273894851642727389985164272739048616427273909861642727391486164272739198616427273924861642727392986164272739348716427273939871642727394487164272739498716427273954871642727395987164272739648716427273969871642727397488164272739798816427273984881642727398988164272739948816427273999881642727400488tail: /tmp/a.out:文件已截断
16427274009891642727401489164272740198916427274024891642727402989164272740348916427274039891642727404489164272740499016427274054901642727405990164272740649016427274069901642727407490164272740799016427274084901642727408991164272740949116427274099911642727410491164272741099116427274114911642727411992tail: /tmp/a.out:文件已截断
1642727412492164272741299216427274134921642727413992tail: /tmp/a.out:文件已截断
1642727414492tail: /tmp/a.out:文件已截断
1642727414993tail: /tmp/a.out:文件已截断
164272741549316427274159931642727416493tail: /tmp/a.out:文件已截断
1642727416993tail: /tmp/a.out:文件已截断
1642727417493tail: /tmp/a.out:文件已截断
1642727417993tail: /tmp/a.out:文件已截断
1642727418493tail: /tmp/a.out:文件已截断
1642727418993tail: /tmp/a.out:文件已截断
1642727419494tail: /tmp/a.out:文件已截断
1642727419994tail: /tmp/a.out:文件已截断
1642727420494164272742099416427274214941642727421994
更多推荐
已为社区贡献10条内容
所有评论(0)