Java 如何正确删除catalina.out?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21754274/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to correct delete catalina.out?
提问by user710818
I couldn't restart Tomcat webserver. But catalina.out get very big. I have tried delete on test server and created new empty. But Tomcat doesn't write anymore in new catalina.out. How correct delete/create empty new one ?
我无法重新启动 Tomcat 网络服务器。但是 catalina.out 变得非常大。我尝试在测试服务器上删除并创建新的空。但是Tomcat在新的catalina.out中不再写了。如何正确删除/创建空的新的?
采纳答案by Sergo Pasoevi
If you are using Gnu/Linux or Mac OS X, you can just do:
如果你使用 Gnu/Linux 或 Mac OS X,你可以这样做:
echo "" > catalina.out
or even shorter:
甚至更短:
> catalina.out
回答by fge
In base Tomcat installs, catalina.out
is usually the result of stdout/stderr redirections via the Tomcat launcher script.
在基础 Tomcat 安装中,catalina.out
通常是通过 Tomcat 启动程序脚本进行 stdout/stderr 重定向的结果。
If you run Tomcat on a Unix system, and if you delete the file while Tomcat is running, the problem is that the process will still have a descriptor open to that file and continue to write on it. The solution is therefore to use a program dedicated to handling such cases. For instance, logrotate (which is standard in pretty much all Linux distributions).
如果您在 Unix 系统上运行 Tomcat,并且如果您在 Tomcat 运行时删除该文件,则问题在于该进程仍将打开该文件的描述符并继续在其上写入。因此,解决方案是使用专用于处理此类情况的程序。例如,logrotate(在几乎所有 Linux 发行版中都是标准的)。
回答by Aqura
for me
为了我
echo "" > catalina.out
or
或者
sudo echo "" > catalina.out
didn't work, as the file was created with root/other user privilege
不起作用,因为该文件是使用 root/其他用户权限创建的
sudo truncate -s 0 catalina.out
worked for me. here -s is for size and I am setting the file size to 0
为我工作。这里 -s 用于大小,我将文件大小设置为 0