linux命令

来源:互联网 发布:淘宝店铺布局图片多大 编辑:程序博客网 时间:2024/06/11 17:02

当在远程服务器上面进行一些操作时候,经常会需要使用ssh命令,但是用ssh登录之后,假设长时间没有操作,那么ssh则会自动断开连接。因为ssh的断开,一些耗时长的操作也会因此中断,最终前功尽弃。因此可以使用nohup或者screen命令,让这些任务可以不受ssh的影响。

1.nohup

nohup command形式
如简单的测试

root@VM-63-65-ubuntu:/home/ubuntu# nohup ls -alnohup: ignoring input and appending output to ‘nohup.out’root@VM-63-65-ubuntu:/home/ubuntu# exitexitubuntu@VM-63-65-ubuntu:~$ nohup ls -alnohup: failed to open ‘nohup.out’: Permission deniednohup: failed to open ‘/home/ubuntu/nohup.out’: Permission denied

通过上述可以发现,nohup命令需要使用root权限(使用sudo nohup command也可以);而且ignoring input and appending output to ‘nohup.out’。如果后面发现程序运行有问题,需要结束其运行,也只能通过kill命令去结束它。
链接1中使用的是nohup command &的形式,
这里写图片描述
可以看到两次运行的不同。在命令末尾加上&,是将此命令交给Linux内核去运行一个进程(即后台进程);不加&,命令是在shell的基础上完成的。
ps:可以运行一个耗费时间长的任务,如大文件的传输,判断加与不加&,在关闭shell之后的各自运行状况。

2.screen

首先需要安装screen

sudo apt-get install screen
#screen

screen回车后,输入自己的命令,这样程序就不会因为ssh中断的影响。通过man screen,可以知道screen的一些用法选项。
screen,运行之后,直接回车,就可以进入到screen中了。
ctrl+a ,d 三个键一起按,就可以回到screen之前的命令行界面了
screen -ls 查看所有的screen的列表
screen -r screenID 重新回到指定ID的screen中

参考链接

1.http://blog.csdn.net/smstong/article/details/5872309
2.http://blog.sina.com.cn/s/blog_a000da9d01015ljg.html

0 0
原创粉丝点击