The main purpose of GNU screen is to allow you to run several terminals “in one”, without the need to log into remote (or local, if needed) system.
This is done by spawning virtual terminals (screens or windows) inside the terminal.
Another, maybe even more useful feature of screen is, that it is persistent. You can easily detach from the session, and log out of the remote server, while any programs you left running in the screen session will stay alive, in a similar way they would with nohup, while having the interactiveness of terminal still available. Afterwards, you can resume previous session once you log back in.
Easiest way to start screen is using the
command. This command attempts to resume “youngest” previous instance of screen, and if there is no such, it creates a new one.
It’s better to use -R variant, as you might have a previous session already running, that you forgot about (happens to me all the time).
You might also use screen -r, that resumes previous session, or prints what sessions are running in case there’s more than one. But it does not start a new one if there is none.
Once inside of the screen terminal, you can use all just like in the usual terminal (with exception of browsing of history, see scrollback mode further on). See man screen(1) for many more details.
Additional functionality is available via Ctrl+a (shortened here as C-a) plus command letter. These are:
C-a c … create new window
C-a 0..9 … skip to window number 0..9
C-a – … skip to a blank window (good as a screen saver)
C-a C-a … skip to previously used window
C-a n … skip to next window
C-a p … skip to previous window
C-a t … show time (system info)
C-a v … show version (good for checking “are we in screen?”)
C-a w … show list of windows
C-a “ … show interactive list of windows, where you can choose which to use
C-a A … allows you to enter a title for the window that will appear in above lists
C-a * … show list of attached displays
C-a C … clear screen
C-a i … show info
C-a N … show current window number
C-a x … lock screen session
C-a z … suspend screen (just like Ctrl+z in terminal – use fg to get back)
C-a d … detach (use `screen -R` to get back)
C-a k … kill this window
C-a \ … kill all windows and quit
C-a esc … enter copy-scrollback mode
Of course, you can always use exit to close the window, just like with a normal terminal. Once you close the last window, the screen terminates.
Copy-scrollback mode is a special mode where you can easily go back through the output (history), just like in modern terminals.
Note: On some systems, screen shows a startup message on each run; if you want to avoid this, simply add startup_message off into your ~/.screenrc file. You can always view this info from screen using C-a , .
Notice: The above is only a handful of the basic commands! Beyond this, you can easily split the view to have more windows in one, monitor what’s going on, and much more.