How to install and use Linux screen

July 2, 2024 / Command Line

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:

  1. Open your terminal.
  2. Update your package list:
    sudo apt update
  3. Install Screen:
    sudo apt install screen

On Red Hat/CentOS-based Systems:

  1. Open your terminal.
  2. Update your package list:
    sudo yum check-update
  3. Install Screen:
    sudo yum install screen

On Fedora:

  1. Open your terminal.
  2. Update your package list:
    sudo dnf check-update
  3. Install Screen:
    sudo dnf install screen

Basic Usage

  1. Start a Screen Session:
    screen
  2. Detach from the Screen Session:
    Press ‘Ctrl-a’ then ‘d’. This detaches you from the screen session and returns you to the regular terminal.
  3. List Active Screen Sessions:
    screen -ls
  4. Reconnect to a Screen Session:
    screen -r <session_id>
    Replace <session_id> with the ID of the session you want to reconnect to.
  5. Create a Named Screen Session:
    screen -S session_name
    Replace session_name with a name of your choice.
  6. Kill a Screen Session:
    1. To kill a specific session:
      screen -X -S <session_id> quit
    2. To kill all sessions:
      screen -ls | grep Detached | awk ‘{print $1}’ | xargs kill

Useful Commands Inside Screen

  1. Create a New Window:
    Press Ctrl-a then c
  2. Switch Between Windows:
    Press Ctrl-a then the window number (e.g., 0, 1, etc.).
  3. List All Windows:
    Press Ctrl-a then w.
  4. 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:

  1. Set a Status Line:
    hardstatus alwayslastline
    hardstatus string “%{= kG}%-Lw%{= kY}%50>%n%f* %t%{= kG}%+Lw%<“
  2. 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.

 

 

Spread the love