The computer screen
command is a terminal multiplexer, which essentially manner it allows you to run multiple terminal sessions within a single window. Ever needed to arrange long-running tasks or keep your sessions alive even after you’ve logged out? That’s where computer screen comes into play.
The beauty of computer screen
is its skill to detach and reattach sessions, making it extraordinarily useful for a ways flung artwork, long-running scripts, or any activity that calls so that you can hop between multiple terminal house home windows. Typically comparable directions include computer screen -r
to reattach a session, computer screen -ls
to file full of life sessions, and Ctrl + A, then D to detach a session without terminating it.
So, whether or not or no longer you’re a tool administrator juggling moderately a large number of tasks or a developer running multiple processes, computer screen is a command you’ll need to add to your Linux toolkit. Be told without delay to learn to harness its entire potential.
Not unusual syntax for computer screen
command:
computer screen [OPTIONS] [SESSION NAME]
1. Create a session with specified identify
computer screen -S [file]
The -S
risk creates a brand spanking new window throughout the computer screen and names it.
Example:
particular person@hostname:~$ computer screen -S my_session
After running this command, you’ll be throughout the new computer screen session named my_session
. You won’t see the session identify at once throughout the terminal, then again you’ll file all full of life sessions by way of detaching from the prevailing session (by way of pressing Ctrl + A followed by way of D) and then running computer screen -ls
.
Trend output for computer screen -ls
after detaching:
particular person@hostname:~$ computer screen -ls There is a computer screen on: 12345.my_session (Detached) 1 Socket in /var/run/computer screen/S-user.
In this example, 12345
is the process ID of the computer screen session, and my_session
is the identify you gave to the session.
To reattach to this session, you’ll use:
computer screen -r 12345
Or if you happen to named your session:
computer screen -r my_session
This may most likely raise you once more to the computer screen session you detached from.
2. Document all computer screen processes
computer screen -ls
This option displays all lately open house home windows, at the side of those running throughout the background.
Example:
The output will maximum incessantly look something like this:
There are screens on: 12345.pts-0.hostname (Detached) 67890.pts-1.hostname (Attached) 2 Sockets in /var/run/computer screen/S-username.
Proper right here’s a breakdown of the output:
12345.pts-0.hostname
and67890.pts-1.hostname
are the identifiers for the computer screen sessions.12345
and67890
are the process IDs (PIDs) of the computer screen sessions.pts-0
andpts-1
indicate the terminal sorts.hostname
is the identify of the host machine where the computer screen sessions are running.- (
Detached
) or (Attached
) indicates the status of the computer screen session. Detached
means that the session is working throughout the background and not lately hooked as much as any terminal.Attached
means that the session is lately being regarded as in a terminal window.2 Sockets
in/var/run/computer screen/S-username
indicates the selection of computer screen sessions and the record where the session sockets are stored. username is the identify of the one who owns the sessions.
3. Reattach the Terminal’s session
computer screen -r [filename]
Use this technique to reattach a computer screen session which was once detached in earlier.
Example:
Let’s say you’ve a long-running process, like downloading a large file, and you want to stick it running even after you’ve logged out. You’ll be capable to use computer screen to create a brand spanking new session and run the process there.
Create a brand spanking new computer screen session:
computer screen -S my_download_session
This may most likely create a brand spanking new computer screen session named my_download_session
.
Run your long-running process:
wget http://example.com/large-file.zip
Detach from the computer screen session:
Press Ctrl + A followed by way of D to detach from the session. The session will continue running throughout the background.
Log off or close the terminal:
At this degree, you’ll safely log out or close the terminal. The download will continue throughout the background.
Reattach to the computer screen session:
Later, when you want to check the advance or reattach to the session, you’ll use the computer screen -r
command.
computer screen -r my_download_session
This may most likely reattach you to the computer screen session named my_download_session
, and also you’ll see the advance of your download or each and every different long-running process.
If you have multiple detached sessions and likewise you’re not certain what the session names are, you’ll file them with:
computer screen -ls
This may most likely show you a list of all the detached and connected computer screen sessions, and also you’ll make a selection the one you want to reattach to.
4. Detach a session
computer screen -d [file]
The -d
risk is used to detach the computer screen session, allowing it to be reattached later.
Example:
Proper right here’s a step-by-step example to expose how computer screen -d [filename]
can be used:
Step 1: Create a New Show Session with a Identify
First, create a brand spanking new computer screen session and gives it a name, for example “my_session
“:
computer screen -S my_session
Step 2: Run Some Directions throughout the Show Session
After creating the session, you’ll be within it. You’ll be capable to run some directions like:
ls echo "Hello, Global!"
Step 3: Detach the Show Session Manually
You’ll be capable to detach from the computer screen session manually by way of pressing Ctrl + A followed by way of D. This may most likely raise you once more to your distinctive terminal, then again the session “my_session
” will however be running throughout the background.
Step 4: Reattach to the Show Session
You’ll be capable to reattach to the session the usage of:
computer screen -r my_session
Step 5: Detach the Show Session The use of -d
Now, let’s say you could be in another terminal and you want to detach the session “my_session
” without reattaching to it. You’ll be capable to use the -d
risk like this:
computer screen -d my_session
This may most likely detach the session “my_session
” if it’s lately hooked as much as any terminal, without terminating it. You’ll be capable to later reattach to it the usage of computer screen -r my_session.
computer screen -X [sharing_session]
This option we could in two folks to log into the equivalent account from different puts.
Example:
Proper right here’s a simple example to expose the way you’ll use computer screen -X
to send a command to a running computer screen session:
Step 1: Create a New Show Session
First, open a terminal and create a brand spanking new computer screen session named “my_session
“:
computer screen -S my_session
Step 2: Detach from the Show Session
You’ll be capable to detach from the computer screen session by way of pressing Ctrl + A followed by way of D.
Step 3: Send a Command to the Show Session from Every other Terminal
Open another terminal window and use the computer screen -X
command to send a command to the “my_session
” computer screen. For instance, let’s send the surrender command to terminate the session:
computer screen -S my_session -X surrender
This may most likely terminate the "my_session" computer screen session.
Additional Linux directions:
List Operations | rmdir · cd · pwd · exa · ls |
Report Operations | cat · cp · dd · much less · contact · ln · rename · extra · head |
Report System Operations | chown · mkfs · find |
Networking | ping · curl · wget · iptables · mtr |
Search and Text Processing | in finding · grep · sed · whatis · ripgrep · fd · tldr |
System Wisdom and Keep an eye on | env · historical past · most sensible · who · htop · glances · lsof |
Individual and Session Keep an eye on | display screen · su · sudo · open |
The post Tips on how to Use the Display Command in Linux appeared first on Hongkiat.
Supply: https://www.hongkiat.com/blog/linux-command-screen/
0 Comments