🟤GNU Screen / tmux

Screen

GNU Screen creates a 'screen' in background and runs command from shell or script.

apt install screen

In your terminal, execute the screen command and press space or enter key to close the intro window. you should see no difference after doing so.

then run your command in that open screen session and send it to background with Ctrl+Z .

then type in bg to send the screen session itself to the background as well.

after this you will be back to screen and by typing screen -d the screen session will be sent to your default shell background in that terminal.

now the application is running in background and terminating the terminal or the SSH session will not terminate the process.

If you want to launch and connect to screen:

screen CMD

If you want to launch and not connect to screen:

screen -dm CMD

Works with sessions too:

screen -Sdm NewDetachedSessionName CMD

You can send keypresses to CMD with stuff:

screen -S NewDetachedSessionName -X stuff "keypresses"

To send a new-line, include or ^M or $'\n' with the keypresses.

irst create new session :

screen -dmS [session_name]

then attach command or script to run in session created:

screen -x [session_name] [script.sh]

tmux

Terminal multiplexer

Last updated