关于nohup命令

nohup java -jar Test.jar --server.port=443 > console.log 2>&1 &

  • 关于nohup命令
  • when using the command shell, prefixing a command with nohup prevents the command from being aborted automatically when you log out or exit the shell. 
  • the name nohub stands for "no hangup." The hangup signal, which is normally sent to a process to inform it that the user has logged off(or "hung up"), is intercepted by nohub, allowing the process to continue running.
  • If standard input is a terminal, nohup redirects it from /dev/null. Therefore, terminal input is not possible when running a command with nohup.
  • If standard output is a terminal, command output is appended to the file nohup.out if possible, or $HOME/nohup.out otherwise.
  • If standard error is a terminal, it is redirected to standard output.
  • To save output to a file named file, use "nohup command > file".

 

  • 英文解释的很清楚,也很容易理解 
  • nohup命令可以让你退出shell或登录时,命令仍然在后台运行,通常我们是通过在命令最后面添加&来使得命令在后台运行的,但关闭shell或退出登录时,服务就挂了;
  • 如果在终端运行nohup,使用<来输入参数是不行的,它重定向输入到了/dev/null,它的默认输出是当前目录下的nohup.out
  • 至于我自己为什么会用到nohup,是因为之间在服务器上跑jar包时,总是意外终端,后来才发现是因为退出了shell的原因

 

关于文件重定向

  • 在shell中,每个进程都和三个系统文件相关联:标准输入stdin,标准输出stdout和标准错误stderr,三个系统文件的文件描述符分别为0,1和2。
  • > console.log 很容易理解就是 重定向标准输出到console.log
  • 2>&1 的意思就是将标准错误也输出到标准输出当中。至于为什么在1前面有个取地址的符号,因为&1就代表标准输出
  • 使用下面的例子来练习下
    • ls 2>1测试,不会报没有2文件的错误,但会输出一个空的文件1,注意>符号左右别加空格,否则会报错;
    • ls xxx 2>1测试,没有xxx这个文件的错误输出到了1中;
    • ls xxx 2>&1测试,不会生成1这个文件了,不过错误跑到标准输出了;
    • ls xxx >out.txt 2>&1, 实际上可换成 ls xxx 1>out.txt 2>&1;重定向符号>默认是1,错误和输出都传到out.txt了

转载于:https://www.cnblogs.com/wjf0/p/9229403.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值