Linux Screen is a powerful tool that lets you to manage multiple terminal sessions from a single window. It is particularly useful for running long processes, as you can disconnect from the session and reconnect later without interrupting the running processes.
Here is how to install and use Linux Screen –
Installation
On Debian/Ubuntu-based Systems:
- Open your terminal.
- Update your package list:
sudo apt update - Install Screen:
sudo apt install screen
On Red Hat/CentOS-based Systems:
- Open your terminal.
- Update your package list:
sudo yum check-update - Install Screen:
sudo yum install screen
On Fedora:
- Open your terminal.
- Update your package list:
sudo dnf check-update - Install Screen:
sudo dnf install screen
Basic Usage
- Start a Screen Session:
screen - Detach from the Screen Session:
Press ‘Ctrl-a’ then ‘d’. This detaches you from the screen session and returns you to the regular terminal. - List Active Screen Sessions:
screen -ls - Reconnect to a Screen Session:
screen -r <session_id>
Replace <session_id> with the ID of the session you want to reconnect to. - Create a Named Screen Session:
screen -S session_name
Replace session_name with a name of your choice. - Kill a Screen Session:
- To kill a specific session:
screen -X -S <session_id> quit - To kill all sessions:
screen -ls | grep Detached | awk ‘{print $1}’ | xargs kill
- To kill a specific session:
Useful Commands Inside Screen
- Create a New Window:
Press Ctrl-a then c - Switch Between Windows:
Press Ctrl-a then the window number (e.g., 0, 1, etc.). - List All Windows:
Press Ctrl-a then w. - Close the Current Window:
Press Ctrl-a then k (followed by y to confirm).
Customizing Screen:
You can customize Screen by editing the ‘~/.screenrc’ file.
Here are a few examples of what you can add:
- Set a Status Line:
hardstatus alwayslastline
hardstatus string “%{= kG}%-Lw%{= kY}%50>%n%f* %t%{= kG}%+Lw%<“ - Enable Scrolling:
defscrollback 10000
Conclusion –
Linux Screen is a multipurpose tool that can greatly enhance your terminal experience by allowing you to manage multiple sessions efficiently. With the ability to detach and reattach sessions, you can maintain long-running processes without interruption.
For more detailed usage and advanced options, refer to the screen man page:
man screen
This is the end of our article. Was not it easy? If you liked it, you will love our support. If you encounter any issues, feel free to contact our technical team for assistance.