Tuesday , 28 June 2016
It's new!!!

The screen command usages and examples – Unix/Linux

The screen command under the Unix is used to execute some process under or inside a screen. That means you can simply detach from the screen and keep working on that server. It is normally very helpful when you need to install some time consuming applications on the server. In this case, you can execute that installation on a screen. The process still runs on that screen, even if you got connection dropped. After sometime you can re-attach that screen and control that process.

Here, I am explaining some common screen command usages and examples:

The command “screen“;

The command “screen” simply open a screen window for your process. You can execute the command over there and can detach the screen safely.

Usage:

screen

Use Ctrl + AD(press CTRL+A followed by d) to detach from screen.

Or, you may open the screen with your process itself.
Example:

screen top

top

In this example, the top command will execute under the screen [Screen0].

Other important switches

To view the screen;

screen -x

Example:

[[email protected] ~]# screen -x
There are several suitable screens on:
        5270.one        (Detached)
        5281.two     (Detached)
Type "screen [-d] -r [pid.]tty.host" to resume one of them.

Usage:

[[email protected] ~]# screen -x 5270.one

List all screens;

screen -ls

Example:

[[email protected] ~]# screen -ls
There are screens on:
        5270.one        (Detached)
        5281.two     (Detached)
2 Sockets in /var/run/screen/S-root.

To attach to a running session;

screen -r

Example:

[[email protected] ~]# screen -r 5270.one 

How to rename the screen session? Is there any way to rename the screen session name?

Yep, we can change the name by using the “-X” switch with “sessionname” parameter.

Syntax

screen -S current.session -X sessionname new.name

Example

I’ve two running session “one” and “two” and I want to change the session name “two” to “backup”. Here is the command to do so:

[[email protected] ~]# screen -ls
There are screens on:
        5270.one        (Detached)
        5281.two        (Detached)
2 Sockets in /var/run/screen/S-root.
# screen -S 5281.two -X sessionname backup

Now see the names;

[[email protected] ~]# screen -ls
There are screens on:
        5270.one        (Detached)
        5281.backup     (Detached)
2 Sockets in /var/run/screen/S-root.

That’s it!

Related:
groupdel, groupmems, groupmod, useradd , usermod , chgrp, chown, ls, head, tail, top, ps, find, crontabftp commands, tar, rpm, rkhunter, Rsync, grep, netstat command switches, netstat command’s practical usages, OpenVZ commands, lsof command

2 comments

  1. Thank arun # screen top shows the running screens on the server am i right?, other way i real love this

    Thank u

Leave a Reply

Your email address will not be published. Required fields are marked *

*