bash 如何避免创建 nohup.out 以及在这种情况下将生成输出的位置?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22589993/
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 avoid creating nohup.out and in this case where the output will be generated?
提问by icm
I am running a matlab script which taking input arguments and output folder is assigned in the function. When I am running nohup like this nohup ./matlabscript.h & then it generates a nohup.out file which is really huge. How do I avoid creating that file? The output folder is assigned, so I am not sure whether an output file needs to be assigned? Thank you
我正在运行一个 matlab 脚本,它接受输入参数并在函数中分配输出文件夹。当我像这样运行 nohup nohup ./matlabscript.h & 然后它会生成一个非常大的 nohup.out 文件。如何避免创建该文件?输出文件夹已分配,所以我不确定是否需要分配输出文件?谢谢
回答by Basile Starynkevitch
As filmorcommented, you could redirectstdoutto some file.
nohup ./script > script.out &
or even redirect both stdoutand stderrto the same file
甚至将stdout和stderr都重定向到同一个文件
nohup ./script > script.out 2>&1 &
or to a different one
或到另一个
nohup ./script > script.out 2> script.err &
To discard an output, redirect it to /dev/null
. The data is basically destructed, so no memory is used. See null(4). If you want to discard both outputs use:
要丢弃输出,请将其重定向到/dev/null
. 数据基本被破坏,所以不使用内存。请参阅null(4)。如果要丢弃两个输出,请使用:
nohup ./script > /dev/null 2>&1 &
nohup(1)notices when both outputs are redirected, thus doesn't create the nohup.out
file (provided none of the two outputs is a terminal, see isatty(3)).
nohup(1)注意到两个输出何时被重定向,因此不会创建nohup.out
文件(假设两个输出都不是终端,请参阅isatty(3))。
I would also recommend considering using batch(1)e.g. with a here document
batch << EOJ
./script > script.out 2>&1
EOJ
Read the advanced bash scripting guide.
阅读高级 bash 脚本指南。