![linux mmap 示例](https://img-blog.csdnimg.cn/img_convert/25152385af3d1275f65325d082e955e8.png)
linux mmap 示例
Linux screen is a tool used to multiplex single ssh terminal easily. The screen has a strong competitor named tmux where we will look next posts. The screen has these abilities to make system administrators life easy.
Linux屏幕是用于轻松多路复用单个ssh终端的工具。 屏幕上有一个强大的竞争对手,名为tmux,我们将在其中查找下一篇文章。 屏幕具有这些功能,可简化系统管理员的工作。
- Multiple screens in a single ssh connection 单个ssh连接中的多个屏幕
- Running commands after ssh disconnectssh断开连接后运行命令
- Resuming screen sessions after ssh disconnectssh断开连接后恢复屏幕会话
- Easily dividing and multiplexing single window轻松分割和复用单个窗口
安装(Install)
Installing screen is easy like below.
安装屏幕很容易,如下所示。
We will use the following command in order to install screen in the deb based distributions like Ubuntu, Mint, Kali, and Debian.
我们将使用以下命令来在基于deb的发行版(如Ubuntu,Mint,Kali和Debian)中安装屏幕。
$ sudo apt install screen
![Install](https://img-blog.csdnimg.cn/img_convert/d5c6e0bbf8d690ae3c879f94158ceaf9.png)
We will use the following command in order to install screen in the rpm based distributions like Fedora, CentOS, Red Hat.
我们将使用以下命令以便在基于rpm的发行版(例如Fedora,CentOS,Red Hat)中安装屏幕。
$ sudo yum install screen
人屏 (Man Screen)
To get more detailed help about screen command use man screen command like below
要获取有关screen命令的更多详细帮助,请使用如下所示的man screen命令
$ man screen
![Man Screen](https://img-blog.csdnimg.cn/img_convert/2071c59f83594f5b4b8229ed47ad5d73.png)
启动Linux屏幕(Starting Linux Screen)
The screen can be started with a simple screen command like below. This will create a new shell same as default shell.
屏幕可以通过如下所示的简单屏幕命令启动。 这将创建一个与默认外壳相同的新外壳。
$ screen
After issuing screen command we will see a notice about shell we will start like below. This page provides summary information about screen shell where we look more details later this post.
发出screen命令后,我们将看到有关shell的通知,我们将开始如下所示。 本页提供有关屏幕外壳的摘要信息,我们将在本文后面提供更多详细信息。
![Starting Linux Screen](https://img-blog.csdnimg.cn/img_convert/3190ba241463ed2d3c2b988704b53962.png)
Press Space to start a shell
按空格键启动外壳
![Starting Linux Screen](https://img-blog.csdnimg.cn/img_convert/82792d74fb4718f4529d0b9a9e0277ee.png)
This is a screen shell which is the same as the bash shell.
这是一个屏幕外壳,与bash外壳相同。
检查屏幕是否运行 (Check If Screen Whether Running)
While working a lot of servers we may need to check if the screen is running. to get status of current shell bash environment variables provides infomraion about terminal with TERM variable. We can see current terminal from here.
在使用许多服务器时,我们可能需要检查屏幕是否正在运行。 获取当前shell bash环境变量的状态可提供有关带有TERM变量的终端的信息。 我们可以从这里看到当前的终端。
![Check If Screen Whether Running](https://img-blog.csdnimg.cn/img_convert/24519cc0efd7e6332c60e8b041f54b77.png)
We can see from the result that the current shell is screen and color support is 256 color with xterm .
从结果中我们可以看到,当前的外壳是屏幕,并且xterm支持颜色为256色。
控制指令 (Control Command)
The screen provides a lot of features. to activate these features some keyboard short cuts used. We call these shortcuts as screen commands. To send command to the screen there is a command named control command. Control command simple specifies next command is about the screen. The default control command is Ctrl+a
屏幕上提供了很多功能。 要激活这些功能,请使用一些快捷键。 我们将这些快捷方式称为屏幕命令。 要将命令发送到屏幕,有一个名为control command的命令。 控制命令简单指定下一个关于屏幕的命令。 默认控制命令是Ctrl + a
Ctrl+a
建立新视窗 (Create New Window)
One of the most used features of the screen is creating new windows. As we stated before the screen can create more than one windows with a single terminal which is very useful for system administrator. Shortcut for creating a new window is
屏幕上最常用的功能之一就是创建新窗口。 如前所述,该屏幕可以通过一个终端创建多个窗口,这对于系统管理员非常有用。 创建新窗口的快捷方式是
Ctrl+a c
First press control command which is by default Ctrl+a and after press c .This will create a new window with shell-like below.
首先按默认为Ctrl + a的控制命令,然后按c 。这将创建一个新的窗口,下面是类似shell的窗口。
![Create Window](https://img-blog.csdnimg.cn/img_convert/4e9e61bb154947392e4e80f310bf1348.png)
切换下一个窗口(Switch Next Window)
In a typical screen usage there will be more than one windows so how can we switch between these windows. In order to switch next window use
在典型的屏幕用法中,会有多个窗口,因此我们如何在这些窗口之间切换。 为了切换下一个窗口使用
Ctrl+a n
切换上一个窗口 (Switch the Previous Window)
Another navigation shortcut for the screen is switching the previous window. Switching between windows do not end the process or close the current window.
屏幕的另一个导航快捷方式是切换上一个窗口。 在窗口之间切换不会结束进程或关闭当前窗口。
Ctrl+a p
从屏幕上拆卸 (Detaching From Screen)
Another very popular usage of the screen is detaching from the screen. Think about these scenarios. We are copying some big files but have go out by closing ssh session. In this situation, we can detach current screen session and then reattach.
屏幕的另一种非常流行的用法是与屏幕分离。 考虑一下这些情况。 我们正在复制一些大文件,但是由于关闭ssh会话而退出。 在这种情况下,我们可以分离当前的屏幕会话,然后重新附加。
Ctrl+a d
列出现有会话 (List Existing Sessions)
To reattach screen sessions we may need to list current existing sessions. The screen provides -list option to list these detached sessions with the date-time information and session name.
要重新附加屏幕会话,我们可能需要列出当前的现有会话。 屏幕上提供了-list选项,以列出这些分离的会话以及日期时间信息和会话名称。
$ screen -list
![List Sessions](https://img-blog.csdnimg.cn/img_convert/71e16a490388a729d4a51fc68b4f2ace.png)
列表画面处理(List Screen Process)
We can look for existing screen sessions in a server. The screen runs as a process like a bash session.
我们可以在服务器中寻找现有的屏幕会话。 屏幕像bash会话一样运行。
$ ps aux | grep screen
![List Screen Process](https://img-blog.csdnimg.cn/img_convert/1e9c0485f86083cd33eda27bff407073.png)
As we see processes id 12336 is our current screen terminal
如我们所见,进程ID 12336是我们当前的屏幕终端
重新连接(Reattach)
We can terminate our connection to the remote server. Then we can reconnect the server and continue with the previously created screen sessions. This is called as reattach
. We will reattach the screen session after connection our server with ssh.
我们可以终止与远程服务器的连接。 然后,我们可以重新连接服务器并继续先前创建的屏幕会话。 这称为reattach
。 将服务器与ssh连接后,我们将重新连接屏幕会话。
$ screen -r
![Reattach](https://img-blog.csdnimg.cn/img_convert/29b8c7fa5bca75a298be25aab6d1b94e.png)
As we see if there is only one screen session to reattach it will automatically be reattached but there are more than one screen session so we should specify which one we want to reattach
如我们所见,如果只有一个屏幕会话需要重新连接,它将自动重新连接,但是有多个屏幕会话,因此我们应指定要重新连接的会话
$ screen -r 12587.pts-12.ubu1
保存终端命令 (Save Terminal Commands)
While working in remote systems we will issue a lot of commands. Remembering these commands can be hard some times especially if we try a lot of things to solve a problem. Screen provides logging commands of running sessions. After a session ends we can look commands issued at this session. To enable command history use following command.
在远程系统中工作时,我们将发出很多命令。 有时候记住这些命令可能很困难,特别是如果我们尝试很多事情来解决问题的话。 该屏幕提供正在运行的会话的日志记录命令。 会话结束后,我们可以查看在此会话中发出的命令。 要启用命令历史记录,请使用以下命令。
Ctrl+a H
![](https://img-blog.csdnimg.cn/img_convert/90708587850e3e9ae1a9c4f46035c5ba.png)
After issuing shortcuts a logfile named screenlog.0 is created.
发出快捷方式后,将创建一个名为screenlog.0的日志文件。
读取历史记录 (Read History Log)
History log files by default named screenlog.id
. They are simple text files and can be read with cat like below.
默认情况下,历史记录日志文件名为screenlog.id
。 它们是简单的文本文件,可以用cat读取,如下所示。
$ cat screenlog.0
![Read History Log](https://img-blog.csdnimg.cn/img_convert/080c0f405e6b7d49d5eb4b308cca62b5.png)
禁用保存终端(Disable Saving Terminals)
After enabling terminal logging we disable it with the same command for enabling like below.
启用终端日志记录后,我们使用相同的启用命令将其禁用,如下所示。
Ctrl+a H
![Disable Saving Terminals](https://img-blog.csdnimg.cn/img_convert/8b6f617f61cc9126e4a92263fab14203.png)
启用监控(Enable Monitoring)
While working multiple windows we can run some command and switch to the next windows. How can we notify if previous windows command is completed? The screen has ability to monitor windows and provides notifications if the commands have finished.
在使用多个窗口时,我们可以运行一些命令并切换到下一个窗口。 我们如何通知以前的Windows命令是否完成? 屏幕具有监视窗口的功能,并在命令完成后提供通知。
Ctrl+a M
![Enable Monitoring](https://img-blog.csdnimg.cn/img_convert/001767ad56fd9d9472e7f27c209c66a4.png)
禁用监控(Disable Monitoring)
Simply issuing same command t enable monitor will disable monitoring for the current window.
只需发出相同的命令t enable monitor将禁用对当前窗口的监视。
Ctrl+a M
![Disable Monitoring](https://img-blog.csdnimg.cn/img_convert/a75a112b9a3b2eff8d601aa29557f4f1.png)
锁屏会话(Lock Screen Session)
Screen session have the ability to lock which is very similar like desktop managers screen lock. To unlock screen current users system password should be entered.
屏幕会话具有锁定功能,这与桌面管理器的屏幕锁定非常相似。 要解锁当前用户的屏幕,应输入系统密码。
Ctrl+a x
![Lock Screen Session](https://img-blog.csdnimg.cn/img_convert/72b4c701ec7a4bba8dff2947d89582ea.png)
停止或退出屏幕(Stopping or Exit Screen)
The best practice screen after usage is closing the screen session with the shortcut below. This will close all windows of the current session.
使用后的最佳实践屏幕是使用以下快捷方式关闭屏幕会话。 这将关闭当前会话的所有窗口。
Ctrl+a k
![Stopping Screen](https://img-blog.csdnimg.cn/img_convert/6cb6866fcd42074eca12f10b36115805.png)
This will ask question “Really kill this window [y/n]” press y to kill session
这将问问题“真的杀死这个窗口[y / n] ”按y杀死会话
linux mmap 示例