bash 我可以更改 nohup.out 的名称吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4549489/
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
Can I change the name of `nohup.out`?
提问by David LeBauer
When I run nohup some_command &
, the output goes to nohup.out
; man nohup
says to look at info nohup
which in turn says:
当我运行时nohup some_command &
,输出变为nohup.out
; man nohup
说看,info nohup
这又说:
If standard output is a terminal, the command's standard output is appended to the file 'nohup.out'; if that cannot be written to, it is appended to the file '$HOME/nohup.out'; and if that cannot be written to, the command is not run.
如果标准输出是终端,则命令的标准输出将附加到文件“nohup.out”;如果无法写入,则将其附加到文件“$HOME/nohup.out”;如果无法写入,则不会运行该命令。
But if I already have one command using nohup
with output going to /nohup.out
and I want to run another, nohup
command, can I redirect the output to nohup2.out
?
但是,如果我已经有一个命令nohup
与输出一起使用/nohup.out
并且我想运行另一个nohup
命令,我可以将输出重定向到nohup2.out
吗?
回答by ismail
nohup some_command &> nohup2.out &
and voila.
瞧。
Older syntax for Bash version < 4:
Bash 版本 < 4 的旧语法:
nohup some_command > nohup2.out 2>&1 &
回答by Godsmith
For some reason, the above answer did not work for me; I did not return to the command prompt after running it as I expected with the trailing &. Instead, I simply tried with
出于某种原因,上述答案对我不起作用;运行它后,我没有返回到命令提示符,正如我预期的那样,尾随 &。相反,我只是尝试
nohup some_command > nohup2.out&
and it works just as I want it to. Leaving this here in case someone else is in the same situation. Running Bash 4.3.8 for reference.
它就像我想要的那样工作。留在这里以防其他人处于相同的情况。运行 Bash 4.3.8 以供参考。
回答by TrueY
As the file handlers points to i-nodes (which are stored independently from file names) on Linux/Unix systems You can rename the default nohup.out
to any other filename any time after starting nohup something&
. So also one could do the following:
由于文件处理程序指向 Linux/Unix 系统上的 i-nodes(独立于文件名存储)您可以nohup.out
在启动后随时将默认值重命名为任何其他文件名nohup something&
。因此,也可以执行以下操作:
$ nohup something&
$ mv nohup.out nohup2.out
$ nohup something2&
Now something
adds lines to nohup2.out
and something2
to nohup.out
.
现在something
增加了线路nohup2.out
和something2
至nohup.out
。
回答by Irshad Khan
Above methods will remove your output file data whenever you run above nohup command.
每当您在 nohup 命令之上运行时,上述方法都会删除您的输出文件数据。
To Append output in user defined fileyou can use >>
in nohup command.
要在用户定义的文件中附加输出,您可以>>
在 nohup 命令中使用。
nohup your_command >> filename.out &
This command will append all output in your file without removing old data.
此命令将在您的文件中附加所有输出,而不会删除旧数据。