<br> ## What is ‘Screen’ command in Linux? The “**screen**” command in Linux is a command-line utility that allows you to create and use multiple shell sessions from a single terminal or SSH connection. You can run different commands or programs in each session, and switch between them easily. You can also detach a session and leave it running in the background, and reattach it later when you need it. ==This is useful for running long-running processes that you don't want to interrupt or lose when you close the terminal or log out¹.== In conclusion, the "screen" command in Linux is a powerful tool for users who work remotely and need to manage multiple terminal sessions within a single terminal window. With the ability to detach and reattach to running sessions, users can stay connected to their work, even if their connection is lost. Whether you are a seasoned Linux user or just starting out, the "screen" command is a must-have tool for anyone who spends time working in the terminal. <br> ## Benefits of using Screen Some of the benefits of using screen are: - You can run multiple commands or programs without opening multiple terminals or SSH connections. - You can resume your work from where you left it, even if your terminal or SSH connection is closed or interrupted. - You can share your screen session with another user and collaborate on the same terminal. - You can split your screen into multiple regions and view different sessions in one window². <br> ## Installation To use screen, you need to install it on your Linux system. You can use your package manager to install it. For example, on Ubuntu or Debian, you can use: `sudo apt-get install screen` On CentOS or Fedora, you can use: `sudo dnf install screen` On Arch Linux or Manjaro, you can use: `sudo pacman -S screen` <br> ## Use Screen ### To start a screen session: You can simply type: `screen` This will create a new window with a shell in it. You can run any command or program in this window. To create another window, you can press Ctrl+A followed by C. This will create a new window with a shell in it. You can switch between windows by pressing Ctrl+A followed by N (for next) or P (for previous). You can also press Ctrl+A followed by W to see a list of all windows³. <br> ### To detach a screen session and leave it running in the background: You can press Ctrl+A followed by D. This will return you to your original terminal. ### To see the screen sessions: You can see the list of detached screen sessions by typing: `screen -ls` ### To reattach a screen session: You can type: `screen -r` This will reattach the last detached session. If you have more than one detached session, you need to specify the session ID or name. For example: `screen -r 1234` ### To give a name to your screen session: You can also give a name to your screen session by using the -S option when you start it. For example: `screen -S mysession` This will create a new screen session named mysession. You can reattach it by typing: `screen -r mysession` ### To share your screen session: You can also share your screen session with another user by using the -x option. For example: `screen -x mysession` This will attach to the same screen session as another user who is already attached to it. You can both see and control the same terminal⁴. You can also split your screen into multiple regions and display different windows in each region. To do this, you need to press Ctrl+A followed by S (for split) or | (for vertical split). This will split your current region into two regions. To switch between regions, you need to press Ctrl+A followed by Tab. To display a different window in the current region, you need to press Ctrl+A followed by ' (for prompt) and enter the window number or name. To remove a region, you need to press Ctrl+A followed by X⁵. ### To kill a screen session: Use the `screen -X -S mysession quit` command. Replace `mysession` with the name of the `screen` session you want to kill. There are many more options and features that screen offers, such as logging, locking, copying, pasting, etc. You can read the man page of screen for more details and examples. `man screen` <br> ## References (1) How to Use Linux’s screen Command - How-To Geek. https://www.howtogeek.com/662422/how-to-use-linuxs-screen-command/. (2) screen command in Linux with Examples - GeeksforGeeks. https://www.geeksforgeeks.org/screen-command-in-linux-with-examples/. (3) 9 screen command examples in Linux [Cheat Sheet]. https://www.golinuxcloud.com/screen-command-in-linux/. (4) How to Use Linux Screen to Get Multiple Terminals. https://linuxhandbook.com/screen-command/. (5) How to use screen command in Linux – Its Linux FOSS. https://itslinuxfoss.com/screen-command-linux/. <br> ## Links [[_Index_2_Server]] <br> ## Tags #linux #cli #command #ssh <br>