Use Screen in Linux
Published:
screen command in Linux provides the ability to launch and use multiple shell sessions from a single ssh session.
When you ssh connection is broken, the previous screen session continues to run on the remote machine. You won’t loose your work!
Install screen
On Ubuntu
$sudo apt-get install screen
On CentOS/Fedora
$sudo yum install screen
Common Commands
# list active sessions
$screen -ls
# create a new session
$screen -S <name>
# detach current working session
on your keyboard, press ctrl + a, then press d
# resume an active session (if # of sessions > 1)
$screen -r <name>
# resume an active session (if the session is shown attached)
$screen -d -r <name>
# check the session name when you are using a screen session
$echo $STY
# resume an active session (if # of sessions == 1)
$screen -x
# terminate current session
type exit in the terminal, or press ctrl + a, then k, then y
# terminate session outside the active one
use $screen -ls to list sessions (in the form of [pid].[sessionname])
find out the pid number
run $sudo kill [pid], to kill the session
#wipe a dead session
$screen -wipe
References:
- https://kapeli.com/cheat_sheets/screen.docset/Contents/Resources/Documents/index