基本使用
SSH时可以方便地resume工作
1 # open new screen session 2 screen 3 # restore
# -d: use the-d
option to detach the screen session from the terminal where it's in.
# https://unix.stackexchange.com/questions/240444/cant-resume-screen-says-i-am-already-attached
4 screen -rd <session_number>
Steps Using GNU Screen
- Connect. Connect to a remote server and create a Screen session via
ssh -t <server.domain.name> screen -R
- Detach. When done with the SSH session, use
ctrl-a d
to detach from the session. This also disconnect with the SSH server.- Reconnect. The SSH session is still running actually. When you are ready to resume working with the session, use
ssh -t <server.domain.name> screen -R
again to reconnect, then you are right where you left it.- Terminate. To permanently terminate a Screen session, just disconnect from the server the usual way (
ctrl-d
).Limitation: If you are using apps with graphical interface, not just the command line environment, then
screen
is not suitable for resuming such jobs, and VNC instead would be the ideal choice.https://bobbielf2.github.io/blog/2017/09/14/using-gnu-screen-to-resume-an-ssh-session/
如何Scroll Back以及设置Scroll Buffer大小
ctrl+a+ESC: copy mode
you can scroll
ESC: exit copy mode
ctrl+a+: then type scrollback 999999
Screen has its own scroll buffer, as it is a terminal multiplexer and has to deal with several buffers.
Maybe there's a better way, but I'm used to scrolling using the "copy mode" (which you can use to copy text using screen itself, although that requires the paste command too):
Hit your screen prefix combination (
C-a
/ control+A by default), then hit Escape.Move up/down with the arrow keys (↑ and ↓).
When you're done, hit q or Escape to get back to the end of the scroll buffer.
(If instead of q or Escape you hit Enter or Return and then move the cursor, you will be selecting text to copy, and hitting Enter or Return a second time will copy it. Then you can paste with
C-a
followed by]
.)Of course, you can always use
more
andless
, two commonly used pagers, which may be enough for some commands.https://unix.stackexchange.com/questions/40242/scroll-inside-screen-or-pause-output
Press Ctrl-a then : and then type
scrollback 10000
to get a 10000 line buffer, for example.
You can also set the default number of scrollback lines by adding
defscrollback 10000
to your
~/.screenrc
file.To scroll (if your terminal doesn't allow you to by default), press Ctrl-a ESC and then scroll (with the usual Ctrl-f for next page or Ctrl-a for previous page, or just with your mouse wheel / two-fingers). To exit the scrolling mode, just press ESC.
Another tip: Ctrl-a i shows your current buffer setting.