数据库
MySQL
ORACLE
占位哈哈
占位哈哈
占位哈哈
占位哈哈
占位哈哈
占位哈哈
占位哈哈
占位哈哈
Linux运维
中间件
shell脚本
占位哈哈
占位哈哈
占位哈哈
占位哈哈
占位哈哈
占位哈哈
占位哈哈
首页 动态 发帖 版块 我的
 退出
游客  
等级:
金豆:
经验:
首页  /  linux运维  /  linux命令  /  正文

Linux 之 nohup 命令

  257 
 0
 0
<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, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, 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, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, 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: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;">nohup Command [ Arg … ] [ &amp; ]</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, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, 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, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, 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: &quot;Operator Mono&quot;, 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: &quot;Operator Mono&quot;, 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: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; box-sizing: border-box !important; overflow-wrap: break-word !important;">&amp;</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, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, 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: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; box-sizing: border-box !important; overflow-wrap: break-word !important;">&gt;&nbsp;nohup&nbsp;<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>&nbsp;&gt;&nbsp;a.log&nbsp;2&gt;&amp;1&nbsp;&amp;<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, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, 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&gt;&amp;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 重定向到标准输出 &amp;1 ,标准输出 &amp;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, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, 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, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, 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: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; box-sizing: border-box !important; overflow-wrap: break-word !important;">&gt;&nbsp;nohup&nbsp;wget&nbsp;https://repo.huaweicloud.com/java/jdk/8u172-b11/jdk-8u172-linux-x64.tar.gz&nbsp;&amp;<br data-filtered="filtered" style="margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">//&nbsp;查看后台的进程<br data-filtered="filtered" style="margin: 0px; padding: 0px; outline: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important;">&gt;&nbsp;<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]+&nbsp;&nbsp;Running&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nohup&nbsp;wget&nbsp;https://repo.huaweicloud.com/java/jdk/8u172-b11/jdk-8u172-linux-x64.tar.gz&nbsp;&amp;<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: &quot;Operator Mono&quot;, 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: &quot;Operator Mono&quot;, 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, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, 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: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; box-sizing: border-box !important; overflow-wrap: break-word !important;">&gt;&nbsp;nohup&nbsp;java&nbsp;-jar&nbsp;rumenz.jar&nbsp;&amp;<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, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, 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: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace; border-radius: 0px; font-size: 12px; box-sizing: border-box !important; overflow-wrap: break-word !important;">&gt;&nbsp;nohup&nbsp;bash&nbsp;-c&nbsp;<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&nbsp;&amp;&amp;&nbsp;ls'</span>&nbsp;&gt;&nbsp;output.txt</code></pre>
标签:
作者签名:    楼主  2021-12-02 15:54:28
回复列表
合作伙伴:
Powered by 运维术 8.4.13
© 2017-2024 模板 by 黑衣人
您的IP: 3.144.100.252 , 2024-11-21 19:18:39
Powered by 运维术 8.4.13
© 2017-2024 模板 by 黑衣人
(0) 分享
分享
取消
我的客服