查看bash内部命令:enbale 或者enable command 判断command是否是bash内部命令
[root@localhost ~]# enable enable . enable : enable [ enable alias enable bg enable bind ... [root@localhost ~]# enable alias [root@localhost ~]# enable cat bash: enable: cat: not a shell builtin
nohup只能支持bash内置命令之外的命令,即使你退出登陆,使用nohup该命令也不会中断。
语法:
nohup [命令与参数] --在终端机前台中工作
nohup [命令与参数] & --在终端机后台中工作,命令的输出信息会保存在nohup.out文件中
nohup [命令与参数] > xx.log 2>&1 & --指定命令的输出(包含正确输出和执行过程中的报错信息)定向到xx.log中
[root@localhost ~]# nohup cat install.log & [1] 6648 [root@localhost ~]# nohup: ignoring input and appending output to `nohup.out' exit [root@localhost ~]# ll nohup.out -rw-------. 1 root root 41915 Oct 12 02:16 nohup.out [root@localhost ~]# wc nohup.out 934 1881 41915 nohup.out [root@localhost ~]# wc install.log 934 1881 41915 install.log [root@localhost ~]# diff nohup.out install.log [root@localhost ~]# ll nohup.out -rw-------. 1 root root 41915 Oct 12 02:24 nohup.out [root@localhost ~]# tail -n 1 nohup.out *** FINISHED INSTALLING PACKAGES ***[root@localhost ~]# [root@localhost ~]# tail -n 1 install.log *** FINISHED INSTALLING PACKAGES ***[root@localhost ~]#
重复使用nohup,输出会追加到原本的nohup.out文件中
[root@localhost ~]# cat /tmp/xx01 cat: /tmp/xx01: No such file or directory [root@localhost ~]# nohup cat /tmp/xx01 & [1] 6704 [root@localhost ~]# nohup: ignoring input and appending output to `nohup.out' exit exit [whx@localhost ~]$ su root Password: [root@localhost whx]# cd ~ [root@localhost ~]# ll nohup.out -rw-------. 1 root root 41957 Oct 12 02:19 nohup.out [root@localhost ~]# tail -n 1 nohup.out *** FINISHED INSTALLING PACKAGES ***cat: /tmp/xx01: No such file or directory
定向输出到指定文件中
[root@localhost ~]# nohup cat /tmp/xx01 > test.log 2>&1 & [1] 6727 [root@localhost ~]# ll test.log -rw-r--r--. 1 root root 64 Oct 12 02:20 test.log [1]+ Exit 1 nohup cat /tmp/xx01 > test.log 2>&1 [root@localhost ~]# ll test.log -rw-r--r--. 1 root root 64 Oct 12 02:20 test.log [root@localhost ~]# cat test.log nohup: ignoring input cat: /tmp/xx01: No such file or directory