If the `catalina.out` is deleted after `tomcat` is stopped, it will create a new `catalina.out` once `tomcat` starts and writes to it. But in your case, since `catalina.out` was deleted while `tomcat` was running it is holding up the file reference and writing to the deleted file. You can get rid of this by restarting the `tomcat` server.
I assume you have created with root or another user which leads tomcat to not open it. Check ownership of the created file.
Use `logrotate` tool in `Linux`. It is a log managing command-line tool
in Linux. This can rotate the log files under different conditions.
Particularly, **we can rotate log files on a fixed duration or if the
file has grown to a certain size.** You can click [here][1] for more
info on this.
[1]: https://www.baeldung.com/linux/rotating-logs-logrotate#:~:text=logrotate%20is%20a%20log%20managing,manage%20the%20matching%20log%20files.
This will help you to automate the task of monitoring the log file size and rotate accordingly.
If the `catalina.out` is deleted after `tomcat` is stopped, it will create a new `catalina.out` once `tomcat` starts again and it is totally safe. In case if you remove the `catalina.out` while `tomcat` is running, it will keep on logging to `catalina.out` which is removed already (reference of the file is hold by the `tomcat`) hence the space will not be released. So you will need to restart the `tomcat` sever to release the space. It is not recommended.
Delete/ Move `catalina.out` when `tomcat` server is stopped will not have any problem at all.
But in critical applications running on `tomcat` used by public, this won`t be a good solution since there will be a downtime.
Actually you can clear the log of `catalina.out` file without stopping tomcat with the command below.
sudo cat /dev/null > /opt/tomcat/apache-tomcat-9.0.37/logs/catalina.out
To keep `catalina.out` smaller and get rid of older logs, either one of the following ways can be used:
1. You could use the above `Linux` command and add it to a `CronScheduler`
to run daily/ weekly/ monthly or yearly as preferred.
1. Use `logrotate` tool in `Linux`. It is a log managing command-line tool
in Linux. This can rotate the log files under different conditions.
Particularly, **we can rotate log files on a fixed duration or if the
file has grown to a certain size.** You can click [here][1] for more
info on this.
[1]: https://www.baeldung.com/linux/rotating-logs-logrotate#:~:text=logrotate%20is%20a%20log%20managing,manage%20the%20matching%20log%20files.