用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 <bug-coreutils@gnu.org>.

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,睡一觉回来看,什么工作都完成了.