Showing posts with label screen. Show all posts
Showing posts with label screen. Show all posts

Screen Commands

I have found myself using Byobu by default in Ubuntu machines in order to manage multiple "terminals" in a single session. Byobu has many other advantages, but this is what I primarily use it for. However, Byobu is not as easily installed on CentOS (still can be) and even when it is installed, it doesn't look nearly as good. Also, if there are other administrators that primarily use windows, they can have difficulties when attaching to a byobu session (which can be resolved with some extra steps). Thus, you may find it useful to just use the screen technology that works great in both Ubuntu and CentOS, and is easily installed on both systems. Here is a quick lookup list of commands to interface with the screen tool.

Create A Screen

screen

Create A Screen With A Name

screen -S $NAME

Create A Screen Or Connect To It If Exists

screen -aAxRS $SCREEN_TITLE
This will connect to the screen, even if other people are currently using it which can be useful

List Running Screens

screen -list

This will output a list of all the screens running, which includes their ID and their name.

Two screens can exist with the same name, in which case you may need to make note of the ID instead. No two screens will have the same ID

Restore A Screen

Screen -r $SCREEN_NAME
screen -r $SCREEN_ID

This command will restore a screen by its name or by ID. If there are two screens with the same name, it will throw an error and ask you to resolve by ID

Exit Out of A Screen

Ctrl+a, d

The next couple of "commands" are actually key combos to be executed inside a screen session in order to create an effect similar to below

Create A Split Screen

Ctrl+a, S
Split screens do not appear in screen -list. You will also need to use the next two commands in order to make use of the split.
Make sure to use a capital 's'

Cycle Split Screens

Ctrl+a, tab

Create A Screen

Ctrl+a, c

Close A Split Screen

Ctrl+a, X
Make sure to use a capital 'x'

References

Screen - Attach Multiple Users to a Singe Screen

In Ubuntu, there is a utility called screen which is fantastic for allowing you to create screens whose display is shared between all other terminals within Byobu. This is great for allowing you to teach/show what you are doing to someone in the same terminal and vice versa (you can watch what they do). Byobu is built on screen so as you can imagine, you should be able to do the same in screen on CentOS. Unfortunately typing the screen -r command wont allow you to attach to an already attached session. The trick is to run this command when you create a screen and also when you want to attach to it.

    SCREEN_TITLE=my_screen_title
    screen -aAxRS $SCREEN_TITLE
    Let me explain what these switches mean:
    • a - Force all capabilities into each window's termcap.
    • A - Adapt all windows to the new display width & height. This will observe limitations. E.g if an sshd terminal is smaller than a physical console display (vga attached to the physical machine), the physical display will adapt to be smaller to the size of the terminal. However if the ssh terminal is expanded beyond the limitations of the physical session, then the terminal will be limited to allow all text to always be visible. A dashed line will be shown along the bottom showing the limit. Unfortunately there is no vertical line showing the column limit, but text will just wrap.
    • x - Attach to a not detached screen. (Multi display mode).
    • R - Reattach if possible, otherwise start a new session.
    • S - Name the screen as 'x'. (Multi display mode).

    This will attach to the first screen in the list regardless of whether it is currently attached to or not. I had thought it would attach to the first attached screen but no. If a screen is running that is not attached to, this will be ignored. Someone else who then runs the same command will automatically join you.