Skip to main content

Linux Screen Command Examples

 

 

Installing Screen

Linux screen command already installs on system. You can find screen command in /usr/bin/screen on most RHEL & CentOS distributions. You can find this out from which command in command line.
Source Code   
[root@linuxpathfinder ~]# which screen
/usr/bin/screen
If screen command is not install on server, you can install from redhat package manager (RPM) or with package file as show below:
Source Code   
[root@linuxpathfinder ~]# yum install screen
Resolving Dependencies
--> Running transaction check
---> Package screen.x86_64 0:4.0.3-16.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================
Package                  Arch                     Version                         Repository              Size
====================================================================================================
Installing:
screen                   x86_64                   4.0.3-16.el6                    base                   494 k
Transaction Summary
====================================================================================================
Install       1 Package(s)
Total download size: 494 k
Installed size: 795 k
Is this ok [y/N]: y
Downloading Packages:
screen-4.0.3-16.el6.x86_64.rpm                                                           | 494 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : screen-4.0.3-16.el6.x86_64                                                                   1/1
Verifying  : screen-4.0.3-16.el6.x86_64                                                                   1/1
Installed:
screen.x86_64 0:4.0.3-16.el6
Complete!

Starting Screen Command

As we put all commands on linux server command line, screen command is also started from it:
Source Code   
[root@linuxpathfinder ~]# screen
You will see that you have entered inside of a screen window. Now you can start your work as a normal command line environment. The screen application has its parameters.
Type “Ctrl-a” and “?” without quotes and see all parameters or commands in which guide you how to use screen.

Creating Screen Windows

After entering into screen you just use “Ctrl-a” “c” to create a new window in the default prompt and your old window will be still activated.
If you run any command in newly created screen window and after that switch to another window to do other things. Now you will see previous command in old window will be still running.

Switching Windows

“Ctrl-a” “n” screen command allows you to move forward and back. In the above creating window example to switch on screen window to other screen window, this command “Ctrl-a” “n” switches you to the next window. This command work like a circle around to your first window.
Command with “n” option forward to next window and command with “p” option move to previous window.
Each command in different windows will continue its process until you kill that window.

Detaching From Screen

While using screen command if you need to drop into actual shell. You have a detaching option to exit screen command with “Ctrl-a” “d”. This command has an option to reattach the previous screen. So that we can consider it the powerful part of the screen. For example, if you are using rsync command to copy server data to another server. I would recommend to run rsync command into screen to avoid break the session due to any reason. After detaching the screen your all windows will be still threr and safe.

Reattach Linux Screen

You have an option to reattach the screen. However you detach your connection from the screen or your connection lost due to network or some other reason.
Source Code   
[root@linuxpathfinder ~]# screen -r
Above command reattach to your screen.
If you have multiple screens you may get below message:
Source Code   
[root@linuxpathfinder ~]# screen -r
There are several suitable screens on:
27458.pts-0.linuxpathfinder    (Detached)
27447.pts-0.linuxpathfinder    (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.
There are another option to see a single or multiple screens like:
Source Code   
[root@linuxpathfinder ~]# screen -ls
There are screens on:
27832.pts-0.linuxpathfinder    (Detached)
27899.pts-0.linuxpathfinder    (Detached)
2 Sockets in /var/run/screen/S-root.
Here you specify the screen if you have multiple screens.
Source Code   
[root@linuxpathfinder ~]# screen -r  27458.pts-0.linuxpathfinder

Logging Screen Output

As you are a Linux Administrator and manages many Linux servers like backups, configurations, taking logs etc. So sometime needs recording screen command logs. Let’s say you are using screen command activate with logging function, to activate logging function press “Ctrl-a” “h” . Now you do not need to put down even a single command which you did. When you activate logs function a notification tells you at the bottom left side of the screen. It creates logfile name “screenlog.0″ and save into your home directory.
Everything save into the logfile you write down in screen window. Press again same command to close screen to running log activity.

Getting Alerts on Screen

Another great feature of screen is to monitor a window for any activity. If you are waiting for output of your activity, something compiling or uploading/downloading large files, you can press “Ctrl-a” “m” to look for output at the bottom of the page of your activity.

Lock Screen Session

Lock the screen also have another feature of screen command specially when you need to step away from your system due to any reason. You just need to press “Ctrl-a” “x” shortcut to lock the screen. When you press the shortcut the output become look like as show below.
Source Code   
Screen used by root <root>.
Password:
Now use your Linux password to unlock it.

Leave/Exit Screen

There are two options to leave or exit the screen. First we detach the screen with “Ctrl-a”  “d” and the second option is to exit command to terminating session or use Ctrl-a”  “k” to kill the screen.
There are still a numerous features of screen command. We only discussed such features which are implement on daily basis.

Comments

Popular posts from this blog

Problem: Date Formatting cannot be Changed in Microsoft Excel

In this article, we will learn how to change the date formatting. We will use “Text to Column” wizard to resolve the problem of change the date formatting in Microsoft Excel. Let’s understand the functions: - Text to Column:  “Text to Column” is used for separating the cell content which is depending on the way your data is arranged. You can divide the data on the basis of content in the cell such as space, comma, period, semicolon, etc. Let’s take an example and understand how we can convert the date into Text. We have dates, foramatted as text in column A. Now, we want to convert it into date format.     If we want to convert the formatting into numbers, then we need to follow below given steps:- Select the range A2:A11. Go to Data tab, and click on Text to Columns from the Data tools group.     Covert Text to Columns Wizard – Step1 of 3 dialog box will appear. Select fixed width, and click on Next button.     Skip step-2, and...
How To Remove Gphone Virus Well gphone.exe is nowadays one of the most dangerous virus spreading very rapidly. It is a Trojan and changes your IE homepage and sends tries to open gtalk and yahoo messenger. It even sends messages to gtalk contacts. Its icon is just like that of folder icon and people thinking of folder click on it get infected by the virus. Gphone virus basically is a 260 kb .exe file which looks like a folder and it can take any name of any other folder if you have clicked on the virus folder which looks like a folder but it is not. If you have a folder name ―movies‖ in your D drive it will make a exe file in the folder named movies.exe and if you click on that exe file it too work as a virus. It makes .exe files in all the folders you have with the name of the folder. How to remove this virus Method 1 1. Go to Task Manager then Processes and then click on gphone.exe and click on end process. 2. Manually go to folder where gphone.exe is present and delete it. 3...