The screen Command in Linux
-
What Is
screen
Command in Linux -
Use
screen
Command to Start Screen in Linux -
Use
screen
Command to List All Screen Sessions in Linux -
Use
screen
Command to Attach Screen Session in Linux -
Use
screen
Command to Start Screen Logging in Linux
This tutorial explains using the screen
command in Linux to create, attach, detach, log, and exit screen sessions.
What Is screen
Command in Linux
The screen
command is a bash program used to manage the Linux window. Using the screen command, you can initiate multiple screen sessions. The screen session can also have multiple windows.
The screen
command helps separate processes running on the terminal by putting them in different sessions. The screen
command allows you to switch between sessions and choose which session to attach.
Use screen
Command to Start Screen in Linux
To start the screen
program in Linux. Type screen
as shown below and press Enter.
The above command displays the following output. Press Space, and you will be directed to a terminal.
Once on the terminal, you can run commands as if you are in the normal terminal environment.
We are now inside a terminal session which we started using the screen
command. To detach from the session, press Ctrl + A and D.
You will see similar output to the one below.
Use screen
Command to List All Screen Sessions in Linux
To list all the available screens on our machine, we use the screen
command with the -ls
or -list
option.
The image below shows the available screens on our machine.
Use screen
Command to Attach Screen Session in Linux
We use the screen
command with the -r
option that takes the session ID as an argument to go back to the screen session after detaching it.
We reattach the session with ID 2276
in the image below.
Use screen
Command to Start Screen Logging in Linux
To enable logging when we start a screen session, we use the screen
command with the -L
option. It will create a log file for the screen session in the current screenlog.0
folder.
We start a new screen session with logging enabled in the image below.
Once inside the screen session, we type the following commands, and then we detach the session by typing Ctrl + A and D.
Now that we are outside of the session, we use the ls
command to list the contents of the current directory and pass the output to the grep
command. The grep
command looks for the screenlog
match and displays the line that fits the match.
The image below shows that we have the screen log file named screenlog.0
.
To leave the screen terminal session, you can press Ctrl + A and D to detach the screen. You can also type the exit
command on the terminal, and it detaches the screen.
Using Ctrl + A and K kills the screen.