GNU Screen

From XennisWiki
Jump to: navigation, search

GNU Screen is a software application that can be used to multiplex several virtual consoles, allowing a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session. It is useful for dealing with multiple programs from a command line interface, and for separating programs from the Unix shell that started the program. (Wikipedia)

Installation

apt-get install screen

Usage

Further information: 10 Screen Command Examples to Manage Linux Terminals

Run screen

Enter screen and run your command(s)

$ screen
HERE-SOME-COMMAND
MAYBE-ANOTHER-ONE-HERE

Press [Ctrl] + [a] + [d] to close screen. You get an output like [detached from 28045.pts-2.example]. Or use [Ctrl] + [a] and type :quit to quite the screen.

Re-attach the screen

Restore screen via

screen -r

In the case you have more then 1 screen session, (1) check the available screens with -ls (or -list) and then (2) use -r <session-id> to restore the screen with this session id.

$ screen -ls
There is a screen on:
	28045.pts-2.example	(01/29/16 17:33:24)	(Detached)
1 Socket in /var/run/screen/S-example.
$ screen -r 28045

Detach screen

In the screen use [Ctrl] + [a] + [d] to detach the screen. From the command line use:

screen -d <id>

SSH

ssh <user>@</host> screen -d -m ./path/script

Alternatives

nohup

nohup is a POSIX command to ignore the HUP (hangup) signal. The HUP signal is, by convention, the way a terminal warns dependent processes of logout. Output that would normally go to the terminal goes to a file called nohup.out if it has not already been redirected. (Wikipedia)

nohup /path/script.sh

see Run a nohup command over SSH, then disconnect

See also

External links