screen Command: Tutorial & Examples

Run multiple "tabs" in one terminal session

The screen command in Linux is a terminal multiplexer, which allows you to create and manage multiple terminal sessions within a single terminal window or console. It enables you to run multiple programs or processes in the background while you are logged in to the terminal, and allows you to switch between them or bring them back to the foreground as needed.

Here are some common uses of the screen command:

  • Start a new terminal session: To start a new terminal session within a screen window, you can use the screen command followed by any command you want to run. For example:

    screen ls
    

    This will open a new screen window and run the ls command in it.

  • Detach from a terminal session: To detach from a terminal session and leave it running in the background, you can use the Ctrl-a d key combination. This will close the terminal window and return you to the command prompt, but the program or process you were running within the screen window will continue to run in the background.

  • List available terminal sessions: To list all the available terminal sessions that you have running within screen, you can use the screen -ls command. This will display a list of all the screen windows you have open, along with their session names and process IDs.

  • Reattach to a terminal session: To reattach to a terminal session that you previously detached from, you can use the screen -r command followed by the session name or process ID of the session you want to reattach to. For example:

    screen -r 12345
    

    This will reattach to the terminal session with the process ID 12345.

There are many more options and features available with the screen command. You can use the man screen command to view the full manual for screen and learn more about how to use it.

Info: Here at CleverUptime we use screen a lot to run programs in the background even when we're disconnected from the server. It's also very helpful when your internet connection is not very stable. When the connection breaks up you can log in again and continue where you left off. As an alternative, we also use tmux which offers even more flexibility.

Except where otherwise noted, content on this site is licensed under a CC BY-SA 4.0 license CC BY SA