The screen command usages and examples – Unix/Linux

The screen command under the Unix is used to execute processes inside a screen session.

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

What is inode number in Linux?

Inode number in Linux. It’s simply a reference (index) about the file and directory on the System.

This is an entry in Inode table. This data structure uses to represent a file system object, this can be one of the various things such as file or directory. It’s a unique number for files and directories under a disk block/partition.

Post navigation

Arunlal Ashok

Operations Engineer at Endurance International Group. Linux lover. Like to play on Linux console. I started this blog to share and discuss Linux thoughts.

Always happy for an open discussion! Write to arun (@) crybit (dot) com. Check about me for more details. About this blog and our strong members, check The team CryBit.com
I like to travel. My travelogues are published at Trip Mentor

3 thoughts on “The screen command usages and examples – Unix/Linux

  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 *