如何使用 Unix 重定向重定向滚动文件中的 stdout 和 stderr [英] How to redirect the stdout and stderr in rolling file with Unix redirection

查看:34
本文介绍了如何使用 Unix 重定向重定向滚动文件中的 stdout 和 stderr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 java 应用程序,我在 Unix 上从命令提示符运行它.我正在将 stdout 和 stderr 重定向到 console.outconsole.err 文件.由于记录了大量信息,文件大小正在增加.

I have java application which I am running on Unix from the command prompt. I am redirecting stdout and stderr to console.out and console.err files. The file size is increasing because a lot of information is being logged.

我想创建一个滚动文件,当文件大小增加到超过特定大小时,例如,如果 console.out 大小超过 500KB,则应该创建 console1.out.目前我正在使用

I want to create a rolling file, when the file size increases above a particular size, e.g console1.out should get created if console.out size exceeds 500KB. Currently I am using

java MyAppName > logs/Console.out 2> logs/Console.err &

我该怎么做?

推荐答案

pipe 将结果拆分成这样:

Pipe the result to split like this:

java MyAppName |split -b500k - Console.log

每次超过 500k 时,这都会创建一个新文件.有关详细信息和选项,请参阅 split 的手册页.

This will create a new file every time you go over 500k. See the man-page for split for more details and options.

这篇关于如何使用 Unix 重定向重定向滚动文件中的 stdout 和 stderr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆