Linux 之 nohup 命令

系统 Linux
nohup命令可以将程序以忽略挂起信号的方式运行起来,被运行的程序的输出信息将不会显示到终端。

[[436483]]

nohup命令 可以将程序以忽略挂起信号的方式运行起来,被运行的程序的输出信息将不会显示到终端。

无论是否将 nohup 命令的输出重定向到终端,输出都将附加到当前目录的 nohup.out 文件中。如果当前目录的 nohup.out 文件不可写,输出重定向到$HOME/nohup.out文件中。如果没有文件能创建或打开以用于追加,那么 command 参数指定的命令不可调用。如果标准错误是一个终端,那么把指定的命令写给标准错误的所有输出作为标准输出重定向到相同的文件描述符。

命令格式

nohup Command [ Arg … ] [ & ]

参数说明

  •  Command:要执行的命令。
  •  Arg:一些参数,可以指定输出文件。
  •  &:让命令在后台执行,终端退出后命令仍旧执行。

命令后台执行,正常输出和错误输出到a.log文件

  1. > nohup command > a.log 2>&1 & 

2>&1 解释

将标准错误 2 重定向到标准输出 &1 ,标准输出 &1 再被重定向输入到 runoob.log 文件中。

  •  0 – stdin (standard input,标准输入)
  •  1 – stdout (standard output,标准输出)
  •  2 – stderr (standard error,标准错误输出)

后台下载文件 

  1. > nohup wget https://repo.huaweicloud.com/java/jdk/8u172-b11/jdk-8u172-linux-x64.tar.gz &  
  2. // 查看后台的进程  
  3. > jobs  
  4. [1]+  Running                 nohup wget https://repo.huaweicloud.com/java/jdk/8u172-b11/jdk-8u172-linux-x64.tar.gz & 

下载过程中,输出在nohup.out文件中,可以使用tail -f nohup.out动态查看。

后台运行SpringBoot项目 

  1. > nohup java -jar rumenz.jar & 

后台执行bash命令 

  1. > nohup bash -c 'cal && ls' > output.txt  

 

责任编辑:庞桂玉 来源: 良许Linux
相关推荐

2009-12-24 17:04:18

nohup命令

2009-12-23 10:57:20

nohup命令

2020-09-21 05:53:28

Linux命令&

2020-06-18 07:49:47

Linux终端程序

2012-05-10 08:37:54

Linuxxargs

2012-05-11 10:07:55

Linuxfind

2021-09-07 12:27:34

Linuxchmod命令

2012-05-10 08:46:05

Linuxsort命令

2009-07-31 16:14:27

linux cd命令Linux基本命令

2012-05-10 08:55:11

Linuxuniq

2009-10-22 11:36:31

linux磁盘管理

2010-03-18 16:38:39

Linux命令

2009-10-22 10:59:29

linux磁盘命令

2009-10-22 10:54:51

linux磁盘管理命令

2009-10-22 10:50:47

linux磁盘管理命令

2012-02-29 00:38:29

Linux命令

2010-03-18 17:00:57

Linux命令

2010-03-18 17:21:52

Linux命令

2010-03-18 17:13:52

Linux命令

2009-10-27 16:34:02

linux top命令
点赞
收藏

51CTO技术栈公众号