A brief introduction to GNU Screen

Recently, I was looking for a solution to keep the processes running after terminal has been closed … and ended up finding 2 main ways for doing that:

  1. Using nohup command: Which I think is the best and simplest way. You can simply use that with your long running command: nohup your-command &
  2. Using window managers and terminal multiplexers like screen and tmux: Although they can do the job but that’s not what they’re built for!

Actually “GNU Screen” or simply “screen” is a tool that brings you the ability to run multi sessions, detach from a session, resume sessions, splitting window horizontally and vertically, locking a session screen, sharing an SSH screen, etc. tmux is an alternative for screen and it seems to have more popularity among sysadmins! But in this article we stick with the screen for it’s simplicity and availability. You’re able to check tmux man page or github page for more information.

Installing GNU Screen

You can simply install screen using apt (on Debian/Ubuntu) or yum (CentOS/Fedora). Keep in mind that you need root access for installing:

# Ubuntu/Debian
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install screen
# Fedora/CentOS
sudo yum update
sudo yum install screen

If you’re a Mac user you should use Homebrew to install Screen. FYI I had some issues with some features of Screen on Mac (and you may also have).

# MacOS X
brew install homebrew/dupes/screen

Okay, Now how to use it?

Just enter command:


Then you will be entered to a new session inside Screen. you can make many of them and switch between them. For detaching current session window just press ctrl+a then d keys.  For listing created sessions enter following command:

screen -ls

For reattaching to one of them:

screen -r [screen name]

That’s it! You already know the most useful commands. But we’re not finished yet. Screen allows us to do much more (fun) things.

Splitting screen

One of the use full features if you have to monitor your environment through several apps and logs! Screen allows you to split sessions screen horizontally and vertically. Just enter these commands inside a screen session:

# Split display horizontally
Ctrl+a S
# Split display vertically
Ctrl+a |
# Jump to next display region
Ctrl+a tab

Locking sessions

Simply lock your screen session and set a password for it:

# Locking current screen
Ctrl+a x

Here I listed few features of Screen. Feel free to share any other co0l things related to this post in comments section.

One response to “A brief introduction to GNU Screen”

  1. Hamid Faridafshar says:

    As a matter of choice, nohup would get emphasized while you want to start a process just in this init, while others keep going until the process get finished or you exit the virtual terminal manually, so we have to make decision what we wanna do, then choose the appropriate tool.

Leave a Reply

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