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

Fix error 0xc000007b “The Application Was Unable To Start Correctly”

Fix error 0xc000007b “The Application Was Unable To Start Correctly” Windows is one of the most popular OS ( Operating System ) used today by several users. There are lot of versions available for the Windows. The most popular version of the window is Window 7.0. Some user switches to the newest version but still there are lot of people who is using the older version. There is one of the most common error  “The application was unable to start correctly 0xc00007b”  is faced by the all windows user. Today we are going to show you how to solve this error.  Before we get to the solutions of this error let’s take a look at the reason behind this error. There could be any reason of this error but we listed some of the most common reason for this error. The 32-bit app tries to execute on a 64-bit system. You might be trying to play a Game on your PC and after launching the application, error code  0xc00007b  may flash on your screen. You might be...
How to find and remove duplicate files from PC uplicate files can cause all kinds of problems on your computer, taking up precious storage room, confusing your photo or media manager apps, and generally getting in the way of searches and other operations when you'd rather they didn't. You don't have to accept duplicate files as an inevitability of running a PC, though: Here's how to get rid of them. Duplicate files can crop up for all kinds of reasons: Maybe you downloaded a file, forgot it was there, and then downloaded it again; maybe you copied a folder of images and then never got around to getting rid of the originals. Whatever the reason, they clog up your disk space and shouldn't be left to gather dust. For the purposes of this guide we're going to use DupeGuru-it's Lifehacker's pick as the best duplicate file finder for Windows, and it's available for Mac and Linux as well. If you're not taken with DupeGuru, then some of the best al...

Dynamic Host Configuration Protocol (DHCP)

The Dynamic Host Configuration Protocol (DHCP) is a network service that enables host computers to be automatically assigned settings from a server as opposed to manually configuring each network host. Computers configured to be DHCP clients have no control over the settings they receive from the DHCP server, and the configuration is transparent to the computer's user. The most common settings provided by a DHCP server to DHCP clients include: IP address and netmask IP address of the default-gateway to use IP adresses of the DNS servers to use However, a DHCP server can also supply configuration properties such as: Host Name Domain Name Time Server Print Server The advantage of using DHCP is that changes to the network, for example a change in the address of the DNS server, need only be changed at the DHCP server, and all network hosts will be reconfigured the next time their DHCP clients poll the DHCP server. As an added advantage, it is also ...