screen is an excellent tool that allows you to have multiple shell sessions on a single physical terminal.
It’s very helpful when working with remote servers, if you start a screen session on the remote server, whatever you were doing won’t be lost if your connection to the server fails, just connect again to the server, resume the previous screen session and you can continue with your tasks.
Here are some useful screen commands:
To start screen just type screen and then you’ll be in your new terminal. When ready to detach, hit CTRL+a and then press d.
If only one screen is open:
$ screen -R
If more than one screen is open:
1. Get the terminal_id
$ screen -list There are screens on: 29143.pts-0.server1 (06/11/2016 10:13:07 AM) (Detached) 29122.pts-0.server1 (06/12/2016 11:11:34 AM) (Detached) 2 Sockets in /var/run/screen/S-root.
2. Reattach the screen
$ screen -R 29122.pts-0.server1
RECOVER FROM A DISCONNECTED SESSION
If the connection lost when in a screen session, then when you try to connect to that screen session you get the message: There is no screen to be resumed.
To recover the session:
$ screen -d -r 29721.pts-6.bugs
where 29721.pts-6.bugs is the terminal id returned by the command: ‘screen -list’
|Create a new window:
|Kill the current window:
|Kill all windows:
|Switch to the next window:
|Switch to the previous window:
|List available windows:
|Start/stop logging the current window to screenlog.X:
|Split the current region:
|Kill the current region:
|Switch the focus to the next region:
|Delete all regions but current one:
To configure, add the following in $HOME/.screenrc:
where N is the number of lines to keep
|To enter scrollback mode:
|To exit from scrollback mode:
|To move around
|use VI navigation keys, like h, j, k, G, etc
|To search text in scrollback buffer:
|/ (search forward) or ? (search backward)