GNU screen

Category: /knowledge /linux
Tags: linux

Installation

sudo apt install screen

Frequently used commands

Getting in

start a new screen session: screen
attach to a running session: screen -r
the “ultimate attach”: screen -dRR (Attaches to a screen session. If the session is attached elsewhere, detaches that other display. If no session exists, creates one. If multiple sessions exist, uses the first one.)

Escape key

All screen commands are prefixed by an escape key, by default C-a (that’s Control-a, sometimes written ^A). To send a literal C-a to the programs in screen, use C-a a.

Getting out

detach: C-a d
exit screen: exit all of the programs in screen.
force-exit screen: C-a C-\ (not recommended)

Help

See help: C-a ? (lists keybindings)

Window Management

create new window: C-a c
change to last active window: C-a C-a
change to window by number: C-a <number> (only for windows 0 to 9)
change to window by number or name: C-a ' <number or title>
change to next window in list: C-a n or C-a <space>
change to previous window in list: C-a p
kill current window: C-a K (not recommended)

Split screen

split display: C-a S
jump to next display region: C-a tab # then create a new window (C-a c)
remove current region: C-a X
remove all regions but the current one: C-a Q

Misc

redraw window: C-a C-l
enter copy mode: C-a [ (also used for viewing scrollback buffer)
paste: C-a ]
monitor window for activity: C-a M
monitor window for silence: C-a _
enter digraph: C-a C-v
lock (password protect) display: C-a x
enter screen command: C-a :

配置 - 我的 .bashrc

# 这是配置那个tab bar
hardstatus alwaysignore
hardstatus alwayslastline
#hardstatus string '%{=b}%{b}%-w%{.BW}%10&gt;[%n %t]%{-}%+w%&lt; %=%{G}%C%A, %Y-%m-%d'

# create a status line at the bottom of the screen.  this will show the titles and locations of
# # all screen windows you have open at any given time
hardstatus alwayslastline "%{= dR} %-Lw%50>%{= dG}%n%f* %{= dW}%t%{= dR}%+Lw%<"

#
defutf8 on
defflow off

# terminfo and termcap for nice 256 color terminal
# # allow bold colors - necessary for some reason
attrcolor b ".I"

# enable shift-pgup/pgdown to scroll
termcapinfo xterm|rxvt ti@:te@

# screen里面的所有进程退出,screen就自动退出
autodetach on               # default: on

# 退出vim/nano之后自动刷新屏幕
altscreen on

# 启动等待,显示版本
#msgwait 2
#version
# 启动信息
startup_message off # default: on

# 启用beep报错 vi .screenrc 
vbell off26:~$ less .screenrc 

# 默认的shell,不设置的话就是bash
#shell zsh
### some basic stuff
#########################################################################
activity "%"                    # tell me when stuff happens!           #
crlf off                        # no thanks.                            #
defmonitor on                   # turn monitoring on                    #
defscrollback 1000              # please sir, can i have some more?     #
shell -$SHELL                   # i'll take my default shell.           #
term $TERM                      # We'll use whatever is currently used  #

##    Keybindings    ##
# bind some function keys (k1 == F1, etc) for fast navigation through screen windows
# 
# F10改标题
bindkey -k k; title

# map alt-, & alt-p, F11 to switch to the previous tab 
# F11左边的tab
bindkey -k F1 prev
bindkey "^[," prev
bindkey "^[p" prev

# map alt-. & alt-n, F12 to switch to the next tab 
# F12右边的tab
bindkey -k F2 next
bindkey "^[." next 
bindkey "^[n" next 

screen -t workspace
screen -t log 
#screen -t command 
focus
select 0

讨论

提示

  • 如果看不到讨论部分, 请暂时关掉adblock in Firefox/Chrome
  • 本网站使用Javascript实现评论功能, 此处外链对提高您的网站PR没有帮助. (潜台词: 请不要灌水, 谢谢)