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

The Best Web Hosting Services

Are you looking for the best web  hosting  services for your needs? Whether you need a place to host your small personal blog or a major corporate website, the following list will help you identify the best hosts to use. Finding the best web hosting service isn’t quite as straightforward as searching Google and choosing the one with the lowest price. There are a lot of issues to consider, including the reasons for  why  you need hosting and  how  you intend to use it. Once you have a handle on that, finding the right host becomes much easier. Choose one that’s undersized and you’ll end up with website outages and slow page loads, but choose one that’s oversized and you’ll be throwing money away. Defining Your Web Hosting Needs Before choosing your web host, you’ll need to think about your requirements. Consider the following concerns and decide the importance of each item on a scale of 0 to 10 (with 0 being not at all...

Now You Can Use Reliance Jio 4G Services On 2G And 3G Smartphones

Indians will always be at the top in availing any free internet facility. As, Reliance Jio aims to offer free 4G internet to the 90% of Indians, hence, with one of its services now you can use Jio 4G services on 2G and 3G smartphones. Now You Can Use Reliance Jio 4G Services On 2G And 3G Smartphones Who doesn’t want the free internet? Of course, we all want, Indians will always be at the top in availing any free internet facility. Jio, which is also known as Reliance Jio and officially as Reliance Jio Infocomm Limited has already given its users free unlimited 4G data for 90 days. As the Reliance Jio aims to offer free 4G internet to the 90% of Indians along with the free voice calls and messaging services. So, we all must agree that Indians are always at the peak when it comes about available any internet facility. We all know Jio, which is also known as Reliance Jio Infocomm Limited has previously given its users free unlimited 4G data for 90 days. Not only that but even th...

10 Essential Tips To Keep In Mind While Surfing The Internet

BENGALURU: Internet is an amazing resource which is stapled in many people’s day-to-day lives. It is very much informative but at the same time encircled with many dangers. Listed below are the strategies you can follow to stay safe on the internet as stated by Tech Radar India. Use your discretion on social media Online scams crops up almost everywhere in webpage such as an e-mail, tweet, Facebook post, or many other places. Never click on links that do not look like a real address or pop-ups that claim you have won millions of dollars—all these are scams in which one can easily get trapped. Also don’t fall prey to e-mails which ask you to help someone transfer a large amount of money out of their country delineating their long sad story. Hackers can access data through various innovative ways like sharing links of content that they feel the targeted person is likely to click. Be careful of what you are sharing Limit the content that you share on social media. Facebook...