介绍
screen的功能
screen的功能大体有三个:
- 会话恢复:
只要Screen本身没有终止,在其内部运行的会话都可以恢复。这一点对于远程登录的用户特别有用——即使网络连接中断,用户也不会失去对已经打开的命令行会话的控制。只要再次登录到主机上执行screen -r就可以恢复会话的运行。同样在暂时离开的时候,也可以执行分离命令detach,在保证里面的程序正常运行的情况下让Screen挂起(切换到后台)。这一点和图形界面下的VNC很相似。
- 多窗口:
在Screen环境下,所有的会话都独立的运行,并拥有各自的编号、输入、输出和窗口缓存。用户可以通过快捷键在不同的窗口下切换,并可以自由的重定向各个窗口的输入和输出。
- 会话共享:
Screen可以让一个或多个用户从不同终端多次登录一个会话,并共享会话的所有特性(比如可以看到完全相同的输出)。它同时提供了窗口访问权限的机制,可以对窗口进行密码保护。
这三个功能,其实互相交织,组成screen功能繁多的命令集。
安装screen
因为screen是“元老级”的GNU计划项目,所以不管是apt软件源、或者是yum软件源等其他软件源,都存在screen,只需要使用软件源安装命令即可:
CentOS
yum install screen
Debian/Ubuntu
apt install screen
比如:腾讯云轻量应用服务器的Debian镜像,是纯净的Debian镜像,并没有自带screen的,输入screen,会提示screen: command not found,但是我们可以使用apt命令进行安装:
之后,即可使用screen命令:
screen命令集
screen,通常的命令格式为:
screen [-opts] [cmd [args]]
通常情况下,使用一下基础命令即可,高阶命令过多,比较难记。
状态介绍
通常情况下,screen创建的虚拟终端,有两个工作模式:
Attached:表示当前screen正在作为主终端使用,为活跃状态。
Detached:表示当前screen正在后台使用,为非激发状态。
通常情况下,不需要关注上面的状态。
基础命令
这里列举一些我认为常用的screen命令,使用以下命令基本满足日常使用。
1. 帮助查询
screen的帮助文档实在是过于详细,以至于查个命令,可能要查几分钟;但是你可以直接使用帮助命令,查询自己需要的命令:
查询screen提示
screen -help
2. 终端列表
怎么查看已经存在的screen终端呢?很简单,使用命令:
screen -ls
一般是使用-R创建虚拟终端:
使用-R创建Hello
screen -R Hello
这个时候,我们按Ctril+a,再按d,即可保持这个screen到后台并回到主终端:
三种创建方法比较:
使用-R创建,如果之前有创建唯一一个同名的screen,则直接进入之前创建的screen
使用-S创建和直接输入screen创建的虚拟终端,不会检录之前创建的screen(也就是会创建同名的screen)
回到终端
刚刚我们介绍了创建虚拟终端,并回到主终端的方法。那么,如何重新回到虚拟终端呢?
很简单,使用-R或者-r命令即可:
使用screen -r命令
screen -r [pid/name]
其中:
pid/name:为虚拟终端PID或Name
清除终端
有时候,我们的进程已经“守护”完毕,不需要这个虚拟终端了,也就是需要释放资源,如何操作呢?
比较推荐的方法,是进入对应虚拟终端,然后输入:
退出终端
exit
当然,你如果对screen运行程序,确定已经停止运行了,也可以在主终端内,使用命令释放:
使用-R/-r/-S均可
screen -R [pid/Name] -X quit
版权属于: 顾锦歌——发现生活的美!
本文链接: https://main.huat.fun/index.php/archives/41/
本文最后更新于2023年12月07日 ,已超过501天没有更新,若内容或图片失效,请留言反馈。
本文允许转载,但请在转载时请以超链接或其它形式标明文章出处
Your go-to source for leads. We can provide business to business and business to consumer leads, custom-tailored to your needs. CustomDatabases.org
Hi, It is with sad regret to inform you TopDataList.com is shutting down. We are ceasing operations on TopDataList.com and have made our leads available at a $149 once off fee. Visit us on TopDataList.com Regards, Otilia
Hello, from CustomData.click we are a provider of unique databases that could help your business. Please visit us at CustomData.click to see if we can help you. Regards, Ervin
Hello. It is with sad regret to inform you TopDataList.com is shutting down. We have made all our databases available for you for a once off fee. Visit us on TopDataList.com
ZippyLeads.org is running an easter special till the 18th of April. Get all the leads you need for your company with our easter special.
Hello. My name is Johan Fourie and I am looking to sell DataList.biz. We are a data company that has been in the industry for 12 years. We do around $170k/year in revenue. 1) I am looking to sell 50% of the business for $5k. 2) It would be helpful if you are knowledgeable about the Data Business. 3) I am looking for someone that is willing to take over administration, support, client relations. 4) I will continue to do the marketing for new products. 5) You will accept all future income and pay me from it. Please contact me on WhatsApp +27 72 280 1952 or my personal email: johanfourieinc@gmail.com if you are interested in this and we can have a call. Regards, Johan Fourie
Hi, I am interested in some of your products. Please give me a call on +1 304-873-4360
欢迎加入 Typecho 大家族