Screen: Difference between revisions

From Leo's Notes
This page was last edited on 11 September 2019, at 22:20.
m Text replacement - "Category:Linux{{Navbox Linux}}" to "{{Navbox Linux}}Category:Linux"
reorganized content
Line 1: Line 1:
Screen is a terminal multiplexer and serial terminal. It has some useful features including the ability to lock, detach, and reattach a running session.


== Disable Visual Bell ==
== Quick Usage ==
To disable the visual bell for the current screen instance, hit:
Create a new screen with custom screen name:
{{highlight|lang=text|code=
{{highlight|lang=terminal|code=
Ctrl+a Ctrl+g
$ screen -S test
}}
}}


For a permanent fix, put the following into the {{code|~/.screenrc}} file
This will start a new shell instance inside screen. You can see your current screen session by running
{{highlight|lang=text|code=
{{highlight|lang=terminal|code=
vbell_msg "bell: window ~%" # Message for visual bell
$ screen -ls
vbellwait 2 # Seconds to pause the screen for visual bell
There are screens on:
vbell off # Turns visual bell off
        30922.test      (Attached)
}}
}}


 
Any jobs you run in this screen session can persist even if you log out if you detach from this screen session. Detach from a screen session by hitting {{code|Ctrl+a}}, {{code|d}}. This key combination is written as {{code|C-a d}} in the man pages. If you list the screens running again, you can see that the screen is detached.
== Force Background Redraw ==
{{highlight|lang=terminal|code=
Screen will sometimes mess with any background colors set by programs such as vim. This will cause weird visuals in the terminal where background colors are only rendered where there is text.  
$ screen -ls
 
There are screens on:
You can force screen to redraw the entire area such that the background colors are preserved by putting the following in your {{code|.screenrc}} file:
        30922.test      (Detached)
{{highlight|lang=text|code=
defbce on
}}
}}


 
You may reconnect to detached screens by their partial name or PID number.
== Scrollback Buffer ==
{{highlight|lang=terminal|code=
 
$ screen -r 3    # by the partial (but unique) PID number
Edit {{code|.screenrc}} with:
$ screen -r 30922 # or by the full PID number
{{highlight|lang=text|code=
$ screen -r t    # by the partial (but unique) screen name
defscrollback 5000
$ screen -r test  # or by the full screen name
}}
}}


Scroll back in a screen terminal by hitting:
{{code|Ctrl-a [}}


Navigate using:
Scroll back in a screen terminal by hitting {{code|Ctrl-a [}} and then navigate with one of the following keys in the table.
{| class="wikitable"
{| class="wikitable"
! Key
! Key
Line 65: Line 62:
|}
|}


== Rename Screen Session ==
== Tips & Tricks ==
 
=== Rename Screen Session ===
In a screen terminal, enter {{code|Ctrl-a :sessionname}} followed by the new name.
In a screen terminal, enter {{code|Ctrl-a :sessionname}} followed by the new name.


Line 79: Line 78:
}}
}}


== Lock a Session ==
=== Lock a Session ===
You can use screen to lock the virtual terminal by using the {{code|Ctrl-x}} key.
You can use screen to lock the virtual terminal by using the {{code|Ctrl-x}} key.


== Running a command detached ==
=== Running a command detached ===
To run a command in a screen session in the background, use:
To run a command in a screen session in the background, use:
{{code|screen -S screenname -dm command}}
{{code|screen -S screenname -dm command}}


== Running screen through su ==
=== Running screen through su ===
If you are running screen not directly through the terminal (such as through su), you will get the following error message:
If you are running screen not directly through the terminal (such as through su), you will get the following error message:


Line 100: Line 99:
}}
}}


== Serial ==
=== Serial Console ===
You can use screen as a serial console as well.  
You can use screen as a serial console as well.  
{{highlight|lang=terminal|code=
{{highlight|lang=terminal|code=
Line 107: Line 106:


Common baud rates are 9600 or 115200.
Common baud rates are 9600 or 115200.
== Configuration ==
=== Scrollback Buffer ===
Scrollback buffer can be changed by editing {{code|.screenrc}}. Define the following line with the number of lines to scroll back.
{{highlight|lang=text|code=
defscrollback 5000
}}
== Miscellaneous ==
=== Disable Visual Bell ===
To disable the visual bell for the current screen instance, hit:
{{highlight|lang=text|code=
Ctrl+a Ctrl+g
}}
For a permanent fix, put the following into the {{code|~/.screenrc}} file
{{highlight|lang=text|code=
vbell_msg "bell: window ~%" # Message for visual bell
vbellwait 2 # Seconds to pause the screen for visual bell
vbell off # Turns visual bell off
}}
=== Force Background Redraw ===
Screen will sometimes mess with any background colors set by programs such as vim. This will cause weird visuals in the terminal where background colors are only rendered where there is text.
You can force screen to redraw the entire area such that the background colors are preserved by putting the following in your {{code|.screenrc}} file:
{{highlight|lang=text|code=
defbce on
}}


{{Navbox Linux}}[[Category:Linux]]
{{Navbox Linux}}[[Category:Linux]]
[[Category:LinuxUtilities]]
[[Category:LinuxUtilities]]

Revision as of 22:20, 11 September 2019

Screen is a terminal multiplexer and serial terminal. It has some useful features including the ability to lock, detach, and reattach a running session.

Quick Usage

Create a new screen with custom screen name:

$ screen -S test

This will start a new shell instance inside screen. You can see your current screen session by running

$ screen -ls
There are screens on:
        30922.test      (Attached)

Any jobs you run in this screen session can persist even if you log out if you detach from this screen session. Detach from a screen session by hitting Ctrl+a, d. This key combination is written as C-a d in the man pages. If you list the screens running again, you can see that the screen is detached.

$ screen -ls
There are screens on:
        30922.test      (Detached)

You may reconnect to detached screens by their partial name or PID number.

$ screen -r 3     # by the partial (but unique) PID number
$ screen -r 30922 # or by the full PID number
$ screen -r t     # by the partial (but unique) screen name
$ screen -r test  # or by the full screen name


Scroll back in a screen terminal by hitting Ctrl-a [ and then navigate with one of the following keys in the table.

Key Movement
h Move the cursor left by one character
j Move the cursor down by one line
k Move the cursor up by one line
l Move the cursor right by one character
0 Move to the beginning of the current line
$ Move to the end of the current line.
G Moves to the specified line (defaults to the end of the buffer).
C-u Scrolls a half page up.
C-b Scrolls a full page up.
C-d Scrolls a half page down.
C-f Scrolls the full page down.
/ Search forward
? Search backward

Tips & Tricks

Rename Screen Session

In a screen terminal, enter Ctrl-a :sessionname followed by the new name.

Eg:

# screen -ls
There are screens on:
        8570.test       (Attached)
## Hit Ctrl-a :sessionname Hello
# screen -ls
There are screens on:
        8570.Hello      (Attached)

Lock a Session

You can use screen to lock the virtual terminal by using the Ctrl-x key.

Running a command detached

To run a command in a screen session in the background, use: screen -S screenname -dm command

Running screen through su

If you are running screen not directly through the terminal (such as through su), you will get the following error message:

$ screen 
Cannot open your terminal '/dev/pts/0' - please check.

You can remedy this using script:

$ script /dev/null
$ screen  # Rerun script while in a typescript session

Serial Console

You can use screen as a serial console as well.

screen /dev/ttyS0 <baud>[,<options>]

Common baud rates are 9600 or 115200.


Configuration

Scrollback Buffer

Scrollback buffer can be changed by editing .screenrc. Define the following line with the number of lines to scroll back.

defscrollback 5000


Miscellaneous

Disable Visual Bell

To disable the visual bell for the current screen instance, hit:

Ctrl+a Ctrl+g

For a permanent fix, put the following into the ~/.screenrc file

vbell_msg "bell: window ~%" # Message for visual bell
vbellwait 2 # Seconds to pause the screen for visual bell
vbell off # Turns visual bell off


Force Background Redraw

Screen will sometimes mess with any background colors set by programs such as vim. This will cause weird visuals in the terminal where background colors are only rendered where there is text.

You can force screen to redraw the entire area such that the background colors are preserved by putting the following in your .screenrc file:

defbce on