<p style="padding-top: 8px; padding-bottom: 8px; outline-style: initial; outline-width: 0px; max-width: 100%; clear: both; min-height: 1em; font-size: 17px; word-spacing: 3px; letter-spacing: 1px; color: black; line-height: 26px; box-sizing: border-box !important; overflow-wrap: break-word !important;">nohup命令 可以将程序以忽略挂起信号的方式运行起来,被运行的程序的输出信息将不会显示到终端</p><p style="padding-top: 8px; padding-bottom: 8px; outline-style: initial; outline-width: 0px; max-width: 100%; clear: both; min-height: 1em; font-size: 17px; word-spacing: 3px; letter-spacing: 1px; color: black; line-height: 26px; box-sizing: border-box !important; overflow-wrap: break-word !important;">无论是否将 nohup 命令的输出重定向到终端,输出都将附加到当前目录的 nohup.out 文件中。如果当前目录的 nohup.out 文件不可写,输出重定向到$HOME/nohup.out文件中。如果没有文件能创建或打开以用于追加,那么 command 参数指定的命令不可调用。如果标准错误是一个终端,那么把指定的命令写给标准错误的所有输出作为标准输出重定向到相同的文件描述符。</p><h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; outline-style: initial; outline-width: 0px; font-size: 20px; max-width: 100%; letter-spacing: 0.544px; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, "PingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif; background-color: rgb(255, 255, 255); box-sizing: border-box !important; overflow-wrap: break-word !important;">命令格式</h3><p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; outline-style: initial; outline-width: 0px; max-width: 100%; clear: both; min-height: 1em; font-size: 17px; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, "PingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif; background-color: rgb(255, 255, 255); line-height: 26px; word-spacing: 3px; letter-spacing: 1px; box-sizing: border-box !important; overflow-wrap: break-word !important;"><code style="margin: 0px 2px; padding: 2px 4px; outline: 0px; max-width: 100%; font-size: 14px; border-radius: 4px; color: rgb(30, 107, 184); background-color: rgba(27, 31, 35, 0.05); font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;">nohup Command [ Arg … ] [ & ]</code></p><h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; outline-style: initial; outline-width: 0px; font-size: 20px; max-width: 100%; letter-spacing: 0.544px; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, "PingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif; background-color: rgb(255, 255, 255); box-sizing: border-box !important; overflow-wrap: break-word !important;">参数说明</h3><ul data-tool="mdnice编辑器" class="list-paddingleft-2" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; outline-style: initial; outline-width: 0px; max-width: 100%; letter-spacing: 0.544px; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, "PingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif; font-size: 16px; background-color: rgb(255, 255, 255); box-sizing: border-box !important; overflow-wrap: break-word !important;"><li style="outline-style: initial; outline-width: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><code style="margin: 0px 2px; padding: 2px 4px; outline: 0px; max-width: 100%; font-size: 14px; border-radius: 4px; color: rgb(30, 107, 184); background-color: rgba(27, 31, 35, 0.05); font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;">Command</code>:要执行的命令。</li><li style="outline-style: initial; outline-width: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><code style="margin: 0px 2px; padding: 2px 4px; outline: 0px; max-width: 100%; font-size: 14px; border-radius: 4px; color: rgb(30, 107, 184); background-color: rgba(27, 31, 35, 0.05); font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;">Arg</code>:一些参数,可以指定输出文件。</li><li style="outline-style: initial; outline-width: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;"><code style="margin: 0px 2px; padding: 2px 4px; outline: 0px; max-width: 100%; font-size: 14px; border-radius: 4px; color: rgb(30, 107, 184); background-color: rgba(27, 31, 35, 0.05); font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;">&</code>:让命令在后台执行,终端退出后命令仍旧执行。</li></ul><h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; outline-style: initial; outline-width: 0px; font-size: 20px; max-width: 100%; letter-spacing: 0.544px; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, "PingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif; background-color: rgb(255, 255, 255); box-sizing: border-box !important; overflow-wrap: break-word !important;">命令后台执行,正常输出和错误输出到a.log文件</h3><pre data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px; padding: 0px; outline-style: initial; outline-width: 0px; max-width: 100%; letter-spacing: 0.544px; font-size: 16px; background-color: rgb(255, 255, 255); box-sizing: border-box !important; overflow-wrap: break-word !important;"><code style="margin-top: 0px; margin-bottom: 0px; padding: 16px; outline: 0px; max-width: 100%; color: rgb(51, 51, 51); background: rgb(248, 248, 248); display: -webkit-box; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; box-sizing: border-box !important; overflow-wrap: break-word !important;">> nohup <span style="margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: rgb(0, 134, 179); line-height: 26px;">command</span> > a.log 2>&1 &<br data-filtered="filtered" style="margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;"></code></pre><h4 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; outline-style: initial; outline-width: 0px; font-size: 18px; max-width: 100%; letter-spacing: 0.544px; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, "PingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif; background-color: rgb(255, 255, 255); box-sizing: border-box !important; overflow-wrap: break-word !important;"><code style="margin-top: 0px; margin-bottom: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">2>&1 解释</code></h4><p style="padding-top: 8px; padding-bottom: 8px; outline-style: initial; outline-width: 0px; max-width: 100%; clear: both; min-height: 1em; font-size: 17px; word-spacing: 3px; letter-spacing: 1px; color: black; line-height: 26px; box-sizing: border-box !important; overflow-wrap: break-word !important;">将标准错误 2 重定向到标准输出 &1 ,标准输出 &1 再被重定向输入到 a.log 文件中。</p><ul data-tool="mdnice编辑器" class="list-paddingleft-2" style="margin-top: 8px; margin-bottom: 8px; padding-left: 25px; outline-style: initial; outline-width: 0px; max-width: 100%; letter-spacing: 0.544px; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, "PingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif; font-size: 16px; background-color: rgb(255, 255, 255); box-sizing: border-box !important; overflow-wrap: break-word !important;"><li style="outline-style: initial; outline-width: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">0 – stdin (standard input,标准输入)</li><li style="outline-style: initial; outline-width: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">1 – stdout (standard output,标准输出)</li><li style="outline-style: initial; outline-width: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">2 – stderr (standard error,标准错误输出)</li></ul><h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; outline-style: initial; outline-width: 0px; font-size: 20px; max-width: 100%; letter-spacing: 0.544px; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, "PingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif; background-color: rgb(255, 255, 255); box-sizing: border-box !important; overflow-wrap: break-word !important;">后台下载文件</h3><pre data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px; padding: 0px; outline-style: initial; outline-width: 0px; max-width: 100%; letter-spacing: 0.544px; font-size: 16px; background-color: rgb(255, 255, 255); box-sizing: border-box !important; overflow-wrap: break-word !important;"><code style="margin-top: 0px; margin-bottom: 0px; padding: 16px; outline: 0px; max-width: 100%; color: rgb(51, 51, 51); background: rgb(248, 248, 248); display: -webkit-box; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; box-sizing: border-box !important; overflow-wrap: break-word !important;">> nohup wget https://repo.huaweicloud.com/java/jdk/8u172-b11/jdk-8u172-linux-x64.tar.gz &<br data-filtered="filtered" style="margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">// 查看后台的进程<br data-filtered="filtered" style="margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">> <span style="margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: rgb(0, 134, 179); line-height: 26px;">jobs</span><br data-filtered="filtered" style="margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">[1]+ Running nohup wget https://repo.huaweicloud.com/java/jdk/8u172-b11/jdk-8u172-linux-x64.tar.gz &<br data-filtered="filtered" style="margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;"></code></pre><p style="padding-top: 8px; padding-bottom: 8px; outline-style: initial; outline-width: 0px; max-width: 100%; clear: both; min-height: 1em; font-size: 17px; word-spacing: 3px; letter-spacing: 1px; color: black; line-height: 26px; box-sizing: border-box !important; overflow-wrap: break-word !important;">下载过程中,输出在<code style="margin: 0px 2px; padding: 2px 4px; outline: 0px; max-width: 100%; font-size: 14px; border-radius: 4px; color: rgb(30, 107, 184); background-color: rgba(27, 31, 35, 0.05); font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;">nohup.out</code>文件中,可以使用<code style="margin: 0px 2px; padding: 2px 4px; outline: 0px; max-width: 100%; font-size: 14px; border-radius: 4px; color: rgb(30, 107, 184); background-color: rgba(27, 31, 35, 0.05); font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;">tail -f nohup.out</code>动态查看</p><h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; outline-style: initial; outline-width: 0px; font-size: 20px; max-width: 100%; letter-spacing: 0.544px; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, "PingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif; background-color: rgb(255, 255, 255); box-sizing: border-box !important; overflow-wrap: break-word !important;">后台运行SpringBoot项目</h3><pre data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px; padding: 0px; outline-style: initial; outline-width: 0px; max-width: 100%; letter-spacing: 0.544px; font-size: 16px; background-color: rgb(255, 255, 255); box-sizing: border-box !important; overflow-wrap: break-word !important;"><code style="margin-top: 0px; margin-bottom: 0px; padding: 16px; outline: 0px; max-width: 100%; color: rgb(51, 51, 51); background: rgb(248, 248, 248); display: -webkit-box; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; box-sizing: border-box !important; overflow-wrap: break-word !important;">> nohup java -jar rumenz.jar &<br data-filtered="filtered" style="margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;"></code></pre><h3 data-tool="mdnice编辑器" style="margin-top: 30px; margin-bottom: 15px; outline-style: initial; outline-width: 0px; font-size: 20px; max-width: 100%; letter-spacing: 0.544px; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, "PingFang SC", Cambria, Cochin, Georgia, Times, "Times New Roman", serif; background-color: rgb(255, 255, 255); box-sizing: border-box !important; overflow-wrap: break-word !important;">后台执行bash命令</h3><pre data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px; padding: 0px; outline-style: initial; outline-width: 0px; max-width: 100%; letter-spacing: 0.544px; font-size: 16px; background-color: rgb(255, 255, 255); box-sizing: border-box !important; overflow-wrap: break-word !important;"><code style="margin-top: 0px; margin-bottom: 0px; padding: 16px; outline: 0px; max-width: 100%; color: rgb(51, 51, 51); background: rgb(248, 248, 248); display: -webkit-box; font-family: "Operator Mono", Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; box-sizing: border-box !important; overflow-wrap: break-word !important;">> nohup bash -c <span style="margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: rgb(221, 17, 68); line-height: 26px;">'cal && ls'</span> > output.txt</code></pre>
标签: