GNU Screen is a terminal multiplexer that allows users to manage multiple terminal sessions within a single window or remote session. It enables users to split the terminal into several windows, each running a different process, and allows for easy switching between them. Screen also offers features like session persistence, meaning that even if a user gets disconnected, their running processes can continue in the background and can be reattached to later. This tutorial shows how to install GNU Screen on Ubuntu 24.04.
Install GNU Screen
Execute the following command to update the package lists:
sudo apt update
Install GNU Screen:
sudo apt install -y screen
Once installed, you can check the version of GNU Screen with the following command:
screen --version
Testing GNU Screen
To begin using GNU Screen, start a new session in the background with the following command. Here's the basic syntax:
screen -d -m -S session_name myprog arg1 arg2
-d -m
- starts the session in detached mode, meaning it will run in the background without attaching to the terminal.-S session_name
- names the GNU Screen session.myprog arg1 arg2
- the command you want to run inside the GNU Screen session.
For example:
screen -d -m -S test bash -c 'for i in {1..3}; do echo "Hello world"; sleep 2; done > log.txt'
This will start a detached GNU Screen session called test
and run the command in the background. It runs a Bash shell that executes a loop printing "Hello world" three times with a 2-second pause between each print, and redirects the output to a file.
Uninstall GNU Screen
To completely uninstall GNU Screen along with its dependencies, execute the following command:
sudo apt purge --autoremove -y screen
Leave a Comment
Cancel reply