Screen

There’s more to it than I’ve got here. I’m only putting stuff in here than I’m using or find interesting.
For going to the cheatsheet click here.

Linux Screen is great. It allows you:

  • To have multiple shell windows in a single SSH session.
  • Keep it active if you disconnect.
  • Disconnect and reconnect from different locations/machines.
  • Run a long process without being active in the session.

Note that I’m using Minimal CentOS 8 for this.

My specific use case is, that I can start multiple Discord bots on my CentOS VM. Without it, I’d be able to start a single one.

To install screen on CentOS, you need to install the epel packages by typing:

dnf -y install epel-release

The -y parameter just says yes to the installation, so you don’t have to press Y and then ENTER afterwards.
Screen is now installed.

To start a screen, you simply type

screen

And you’re in a new screen.

To detach it, there seems to be no command for it, but the the builtin way is by pressing:

CTRL + A + D

That is on a Windows keyboard, if you’re using a MAC you’d need to use the equivalent.

If you want to name your session, you type

screen -S session_name

and name your session whatever you’re doing with it, or want to name it.

To view your screens, type:

screen -ls

and it will list your current screens.

If you’d like to kill a session, you need the ID of the session. You can get it by typing the command above.
When you have the ID of the session, type:

screen -X -S # quit

# is the ID number.
If you want to kill all screens, type:

pkill screen

For reattaching to a screen, type:

screen -r #

Remember to put in the session ID number from using:

screen -ls

Cheatsheet

CommandExampleDescription
screenscreenStarts a screen.
screen -S sesson_namescreen -S my_sessionStarts a screen with a session name.
CTRL + A + DCTRL + A + DDeattaches the screen you’re in.
screeen -r #screen -r 7752Reattatches the screen with the session ID 7752.
screen -lsscreen -lsLists active sessions.
screen -X -S # quitscreen -X -S 7752 quitCloses the session with the ID 7752.
pkill screenpkill screenCloses all screens.

Powered by BetterDocs

Comments

No Comments

Leave a Reply