查看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