Examples of screen command usage

GNU Screen is a program which allows you run virtual consoles. The advantage is that screen’s console sessions are not broken when network connection (to machine where the console runs) breaks. But it has many other features, which make it really useful.


Let’s start with screen command. It opens a new shell session within screen.


Detach screen (close but keep running on background), command

screen -d

Or shortcut (e.g. when some program runs inside screen)

Crtl+a followed by d

Print screens running on background

screen -ls

Reattachning screen (open screen running on background), is mandatory if there is more that one detached screen

screen -r <PID>

Special case - attaching screen, which is already attachted to another session

screen -d -r <PID>

Custom screen name

screen -S <name>

Screen have many features, which makes it ‘s usage very comfortable. …if were setup correctly:)

Use ~/.screenrc file

Following code extends console scrollback limit and adds an information bar to the bottom of the screen.

defscrollback 10000 
hardstatus on 
hardstatus alwayslastline 
hardstatus string "%{.bW}%-w%{.rW}%n %t%{-}%+w %=%{..G} %H %{..Y} %m/%d %C%a "

screen bar

Multiple windows inside one screen

That’s really cool. Having multiple screen sessions and switch between them with PID number can be annoying. It is better to have only one screen session and multiple windows inside.

Ctrl+a followed by c # Create a new window/tab
Ctrl+a followed by n # Next window/tab
Ctrl+a followed by p # Previous window/tab

Scrolling inside screen

Scrolling inside screen behaves differently, than is ussual. Use following.

Ctrl+a folowed by Esc (will enter copy-mode, can scroll, Esc to return back)

Interesting resources:

#cli #linux