nohup
(no hang-up)命令用于在后台运行程序,使其在用户退出登录后继续运行
nohup
后面,并在命令末尾添加 &
符号。例如:nohup your_command &
这将在后台运行 your_command
,并将输出重定向到名为 nohup.out
的文件。
>
或 >>
将输出重定向到指定文件。例如:nohup your_command > output.log 2>&1 &
这将在后台运行 your_command
,并将标准输出和标准错误输出都重定向到 output.log
文件。
|
)将多个命令连接起来。例如:nohup command1 | command2 | command3 &
这将在后台运行 command1
,将其输出传递给 command2
,然后将 command2
的输出传递给 command3
。
nohup (command1; command2) &
这将在后台运行 command1
和 command2
,并将它们放在同一个子shell中。
注意:在使用 nohup
命令时,请确保了解所运行命令的功能和潜在风险。在某些情况下,长时间运行的后台进程可能会导致系统资源不足或其他问题。