Getting Started With screen For Bioinformaticians
In my experience, being a bioinformatician involves working on many projects throughout the day. Multiple projects means different interactions with the command line and servers for each project. To alleviate these complexities, bioinformaticians use nohup and screen to manage shell – sometimes remote – sessions. If you are a bioinformatician and do not use either, please get to know both as much as possible and as soon as possible.
As mentioned, screen is a linux command that launches multiple and different ssh shell sessions; it is otherwise known as a terminal multiplexer. screen can attach and detach multiple virtual terminals inside a session and continue to run the virtual terminals after being disconnected.
To start screen, first check if it is installed. Typing screen will start the screen session:
$ screen
or check the version:
$ screen –version
The basic building blocks for a screen command are as follows:
$ screen <-flag> <command arguments>
There is a list of possible flags, followed by a space and then the command arguments for that flag. There are also keyboard shortcuts that will be discussed after the basics are covered.
Attach: Connect screen From Your Terminal
To begin our exploration, the -S flag starts a new screen session with a session name:
$ screen -S <name>
A good and descriptive screen session name is highly recommended. This could be the name of the project, including the date, client name and bioinformatician initials. For example, if you are running multiple RNAseq experiments, a screen name such as “RNAseq” is not sufficient.
A screen shell session has been created with a window. To create a new window within the session, hold the keys Ctrl+a c
To list all screen sessions, type:
$ screen -ls
To attach to a running session, type:
$ screen -x
Or to attach to a running session with a name, type:
$ screen -r <name>
Windows
Interacting with screen can also be done though quick keyboard shortcuts, such as the following illustrates.
To create a new window, use the keys Ctrl-a c
To change to window by number, use the keys Ctrl-a <number>
To change to next window in list, use the keys Ctrl-a n or Ctrl-a <space>
To change to previous window in list, use the keys Ctrl-a p or Ctrl-a <backspace>
Detach: Disconnect screen From Your Terminal
To detach a running session, such as “RNA-seq_<tissue>_<client>_<initials>_20231217” type:
$ screen -d <name>
Or you can also use the keys Ctrl+a d
It is important to note that the shell session running in the screen session will continue to run after detaching from the screen session.
Terminate Windows
To end the current window sessions, use the keys Ctrl+a k
To end the all window sessions, use the keys Ctrl+a \
Quit: Kill All Windows And Terminate Screen
To quit screen, use the keys and then type Ctrl+a : quit
Quick Exit
To detach and log out, use the keys Ctrl-a D D
This was a quick introduction to Linux's screen which must be in every bioinformatician’s daily toolbox. By using screen, a bioinformatician will be able to create multiple shell sessions from a single screen sessions, navigate through different windows within screen, and detach, resume or terminate screen sessions.