具有“恢复会话”function的终端仿真器,如Mac终端

Mac终端能够恢复以前的会话。 我刚刚重启MacBook,当终端打开时,我以前的所有命令都显示在显示屏和所有选项卡中,好像它从未关闭过。 恢复日期只有很少的通知。

是否有一个具有类似function的Ubuntu终端模拟器?

使终端会话持续存在的一个好方法是在服务器上运行“屏幕”会话。 “屏幕”会话为您提供了多个窗口,您可以在该服务器上登录其他计算机或其他任何机器。 您可以在服务器上运行多个“屏幕”会话。 您可以断开连接并重新连接到所需的会话。 ‘screen’是老式的命令行键盘,但非常值得学习和玩,以了解它是如何工作的。 维基百科很好地描述了screen “GNU Screen是一个终端多路复用器,…允许用户在单个终端窗口内访问多个单独的登录会话,…即使用户断开连接,远程进程也会继续运行。” 它有一些很大的优点:

  • 易于安装,可在任何unix(或cygwin)上运行,无需图形(除了终端文本图形)
  • 给出持久的窗口终端会话(只要服务器没有重启)

*屏幕快速入门*

RTFM: gnu.org屏幕用户手册

  • screen – 运行屏幕以简单地创建新会话

  • screen -ls – 列出正在运行的屏幕会话

  • screen -r 20229.pts-2.bangor – 重新连接到会话

*屏幕ESCAPE char默认为Ctrl-a *,除非某些疯狂的looper在.screenrc中更改了它,例如对于不重视进程后台控制的人来说,“escape ^ Zz”。 如果在屏幕上运行,要获得真正的Ctrl-a到终端(转到行首),只需Ctrl-a Ctrl-a

  • ESCAPE c – 创建新的屏幕窗口

  • ESCAPE 0(或1 2 3 4 5 6 7 8 9) – 切换到窗口0(或1 2 ..)

  • ESCAPE p或ESCAPE n – 切换到上一个或下一个窗口

  • ESCAPE“ – 窗口列表

  • ESCAPE h – 显示屏幕帮助:

  Screen key bindings, page 1 of 1. Command key: ^A Literal ^A: a break ^B b help ? monitor M remove X version v clear C history { } next ^@ ^N sp n removebuf = width W colon : info i number N reset Z windows ^W w copy ^[ [ kill K only Q screen ^C c wrap ^R r detach ^D d lastmsg ^M m other ^Z select ' writebuf > digraph ^V license , pow_break B silence _ xoff ^S s displays * lockscreen ^X x pow_detach D split S xon ^Q q fit F log H prev ^H ^P p ^? time ^T t flow ^F f login L readbuf < title A focus ^I meta z redisplay ^L l vbell ^G ^] paste [.] " windowlist -b - select - 0 select 0 1 select 1 2 select 2 3 select 3 4 select 4 5 select 5 6 select 6 7 select 7 8 select 8 9 select 9 I login on O login off ] paste . | split -v :kB: focus prev [Press Space or Return to end.] 

例如,重新连接到会话:

$ screen -ls有以下屏幕:24560.pts-6.mabrowka(Detached)20229.pts-2.mabrowka(附加)2个/ var / run / screen / S-garmon中的套接字。

$ screen -r 20229.pts-2.mabrowska

命令行帮助:

 > $ screen --help Use: screen [-opts] [cmd [args]] or: screen -r > [host.tty] > > Options: > -4 Resolve hostnames only to IPv4 addresses. > -6 Resolve hostnames only to IPv6 addresses. > -a Force all capabilities into each window's termcap. > -A -[r|R] Adapt all windows to the new display width & height. > -c file Read configuration file instead of '.screenrc'. > -d (-r) Detach the elsewhere running screen (and reattach here). > -dmS name Start as daemon: Screen session in detached mode. > -D (-r) Detach and logout remote (and reattach here). > -D -RR Do whatever is needed to get a screen session. > -e xy Change command characters. > -f Flow control on, -fn = off, -fa = auto. > -h lines Set the size of the scrollback history buffer. > -i Interrupt output sooner when flow control is on. > -l Login mode on (update /var/run/utmp), -ln = off. > -ls [match] or > -list Do nothing, just list our SockDir [on possible matches]. > -L Turn on output logging. > -m ignore $STY variable, do create a new screen session. > -O Choose optimal output rather than exact vt100 emulation. > -p window Preselect the named window if it exists. > -q Quiet startup. Exits with non-zero return code if unsuccessful. > -Q Commands will send the response to the stdout of the querying process. > -r [session] Reattach to a detached screen process. > -R Reattach if possible, otherwise start a new session. > -s shell Shell to execute rather than $SHELL. > -S sockname Name this session .sockname instead of ... > -t title Set title. (window's name). > -T term Use term as $TERM for windows, rather than "screen". > -U Tell screen to use UTF-8 encoding. > -v Print "Screen version 4.01.00devel (GNU) 2-May-06". > -wipe [match] Do nothing, just clean up SockDir [on possible matches]. > -x Attach to a not detached screen. (Multi display mode). > -X Execute  as a screen command in the specified session. 

和一个示例.screenrc文件:

 $ cat .screenrc # # Example of a user's .screenrc file # # This is how one can set a reattach password: # password ODSJQf.4IJN7E # "1234" # no annoying audible bell, please vbell on # detach on hangup autodetach on # don't display the copyright page startup_message off # emulate .logout message pow_detach_msg "Screen session of \$LOGNAME \$:cr:\$:nl:ended." # advertise hardstatus support to $TERMCAP # termcapinfo * '' 'hs:ts=\E_:fs=\E\\:ds=\E_\E\\' # make the shell in every window a login shell #shell -$SHELL # autoaka testing # shellaka '> |tcsh' # shellaka '$ |sh' # set every new windows hardstatus line to somenthing descriptive # defhstatus "screen: ^En (^Et)" defscrollback 1000 # don't kill window after the process died # zombie "^[" ################ # # xterm tweaks # #xterm understands both im/ic and doesn't have a status line. #Note: Do not specify im and ic in the real termcap/info file as #some programs (eg vi) will not work anymore. termcap xterm hs@:cs=\E[%i%d;%dr:im=\E[4h:ei=\E[4l terminfo xterm hs@:cs=\E[%i%p1%d;%p2%dr:im=\E[4h:ei=\E[4l #80/132 column switching must be enabled for ^AW to work #change init sequence to not switch width termcapinfo xterm Z0=\E[?3h:Z1=\E[?3l:is=\E[r\E[m\E[2J\E[H\E[?7h\E[?1;4;6l # Make the output buffer large for (fast) xterms. termcapinfo xterm* OL=10000 # tell screen that xterm can switch to dark background and has function # keys. termcapinfo xterm 'VR=\E[?5h:VN=\E[?5l' termcapinfo xterm 'k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~' termcapinfo xterm 'kh=\E[1~:kI=\E[2~:kD=\E[3~:kH=\E[4~:kP=\E[H:kN=\E[6~' # special xterm hardstatus: use the window title. termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]0;screen\007' # our xterm has colors! (rxvt, too) termcap xterm 'AF=\E[3%dm:AB=\E[4%dm' terminfo xterm 'AF=\E[3%p1%dm:AB=\E[4%p1%dm' #terminfo xterm 'vb=\E[?5h$<200/>\E[?5l' termcapinfo xterm 'vi=\E[?25l:ve=\E[34h\E[?25h:vs=\E[34l' # emulate part of the 'K' charset termcapinfo xterm 'XC=K%,%\E(B,[\304,\\\\\326,]\334,{\344,|\366,}\374,~\337' # xterm-52 tweaks: # - uses background color for delete operations # - maps F1-4 to PF1-4 # termcapinfo xterm ut # termcapinfo xterm 'k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS' ################ # # wyse terminals # #wyse-75-42 must have flow control (xo = "terminal uses xon/xoff") #essential to have it here, as this is a slow terminal. termcapinfo wy75-42 xo:hs@ # New termcap sequences for cursor application mode. termcapinfo wy* CS=\E[?1h:CE=\E[?1l:vi=\E[?25l:ve=\E[?25h:VR=\E[?5h:VN=\E[?5l:cb=\E[1K:CD=\E[1J ################ # # other terminals # #make hp700 termcap/info better termcapinfo hp700 'Z0=\E[?3h:Z1=\E[?3l:hs:ts=\E[62"p\E[0$~\E[2$~\E[1$}:fs=\E[0}\E[61"p:ds=\E[62"p\E[1$~\E[61"p:ic@' # Extend the vt100 desciption by some sequences. termcap vt100* ms:AL=\E[%dL:DL=\E[%dM:UP=\E[%dA:DO=\E[%dB:LE=\E[%dD:RI=\E[%dC terminfo vt100* ms:AL=\E[%p1%dL:DL=\E[%p1%dM:UP=\E[%p1%dA:DO=\E[%p1%dB:LE=\E[%p1%dD:RI=\E[%p1%dC ################ # # keybindings # #remove some stupid / dangerous key bindings bind k bind ^k bind . bind ^\ bind \\ #bind ^h bind h #make them better bind '\\' quit bind 'K' kill bind 'I' login on bind 'O' login off bind '}' history # Yet another hack: # Prepend/append register [/] to the paste if ^a^] is pressed. # This lets me have autoindent mode in vi. register [ "\033:se noai\015a" register ] "\033:se ai\015a" bind ^] paste [.] ################ # # default windows # # screen -t local 0 # screen -t mail 1 elm # screen -t 40 2 rlogin faui40 # yeah, please don't re-map the screen ESCAPE char # there could be wailing and gNasHing of teeth # anyway this is how you would do it if you were a cRaZy loOpeR: #escape ^Zz 

对于提出的问题,这不是一个很好的答案。

但它实际上是你正在寻找的答案! > 😉

screen非常有用。

玩得开心!

詹姆士。