歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux服務器 >> SSH登錄linux妙用後台命令

SSH登錄linux妙用後台命令

日期:2017/3/2 16:46:15   编辑:Linux服務器

用SSH管理linux服務器,有時可能要下載點大的軟件或者文件包.又或者要打包一個上5G的文件夾,那是多麼漫長的等待.

更麻煩的是,下載的時候如果SSH 客戶端N久沒動作會斷掉連接,於是下載到一半的東西也會跟著死掉.

當然,你說我可以打開多個SSH客戶窗口來操作,那我不得不說,這是個笨辦法.

比如我想打包一個文件夾,可以用如下的命令

#tar zcvf file.tar.gz /path/document/*

不想等,就把他放到後台去(後面加個&)

#tar zcvf file.tar.gz /path/document/* &

如果你要回來.就使用fg 命令

我們想當然的,下載也是這樣

#wget http://www.phpv.net/file.tar.gz &

但如果你超時或者有事離開而退出SSH 那正在下載的file.tar.gz 文件也會隨之停下了...

怎麼辦?讓我們用nohup 來完成/

NAME
nohup - run a command immune to hangups, with output to a non-tty

SYNOPSIS
nohup COMMAND [ARG]...
nohup OPTION

DESCRIPTION
Run COMMAND, ignoring hangup signals.

--help display this help and exit

--version
output version information and exit

REPORTING BUGS
Report bugs to <[email protected]>.

SEE ALSO
The full documentation for nohup is maintained as a Texinfo manual. If
the info and nohup programs are properly installed at your site, the
command

info nohup

should give you access to the complete manual.

以上是man nohup出來的.

用法很簡單,就在命令前加 nohup

#nohup wget http://www.phpv.net/file.tar.gz

nohup: appending output to `nohup.out'

沒反映...死機了?

CTRL+Z 回到命令行模式...

要避免上面的方法,就加個 & 在命令後面

#nohup wget http://www.phpv.net/file.tar.gz &

#

好了.現在隨便你怎樣exit,睡一覺回來看,什麼工作都完成了

Copyright © Linux教程網 All Rights Reserved