當前位置: 首頁>>技術教程>>正文


如何在 byobu 中保存回滾曆史記錄?

問題描述

我在 byobu 中有一個有趣的終端會話,我想將終端輸出(命令和所有)保存到一個文件中——我該怎麽做?

根據 byobu man page

\\n

Ctrl-a ~ – Save the current window’s scrollback buffer

\\n

這可能確實在做一些事情,但我沒有發現它可能被保存在何處以及以什麽名稱保存的跡象。

最佳方案

對於早期的 byobu 版本,一個老問題仍然無法有效地回答,我再次遇到了需要。

這次我找到了一個可行的解決方案。來自 man byobu

SCROLLBACK, COPY, PASTE MODES

   Each  window  in  Byobu  has  up to 10,000 lines of scrollback history,
   which you can enter and navigate using the alt-pgup and alt-pgdn  keys.
   Exit  this  scrollback mode by hitting enter.  You can also easily copy
   and paste text from scrollback mode.  To do so, enter scrollback  using
   alt-pgup  or  alt-pgdn,  press the spacebar to start highlighting text,
   use up/down/left/right/pgup/pgdn to select the text, and press enter to
   copy  the  text.  You can then paste the text using alt-insert or ctrl-
   a-].
  1. 我點擊 F7 進入回滾模式,

  2. Space開始選擇,

  3. G

    G

    滾動到緩衝區的頂部(感謝@GeorgeMarian)\n

    • 如果這不起作用,請嘗試以下操作:使用大量 Page up: 後跟最大行號(標示在右上角)和 Page up 以到達該頁麵的頂部,

    \n

  4. Enter 複製(到 byobu 的剪貼板,而不是終端/係統),

  5. 然後是終端中的 cat > my-byobu-dump.txt

  6. Alt + Insertctrl + A , ] 粘貼(同樣,來自 byobu 的剪貼板)

  7. Ctrl + D 關閉文件。

次佳方案

或者,您可以為此簡單地使用 Byobu’s hotkey

  • ShiftF7

這會將您的曆史記錄放入 $BYOBU_RUN_DIR/printscreen 中。

第三種方案

如果您習慣不使用 F-keys 那麽這可能對您有用:

  • Ctrl + a , [ : 進入回滾模式

  • Space 進入複製模式(可選)

  • Enter 退出回滾或複製模式

  • Ctrl + a , ] : 粘貼複製的內容

其中 Ctrl + a 是您的 tmux(默認 Byobu 後端)前綴/轉義序列。

第四種方案

如果您將 EDITOR 環境變量設置為 byobu 中的編輯器,則 Shift + F7 隻能按預期工作。出於某種原因,在某些情況下(例如,當我通過 SSH 連接到另一台計算機時),在 ~/.profile 中設置此變量是不夠的。設置它以便 byobu 始終讀取它的一個地方是 ~/.bashrc 。將類似以下內容複製到您的 ~/.bashrc

# Although this is set in ~/.profile, it is set here as well so that in a 
# remote byobu session, Shift+F7 copies the output to a Vim buffer. See:
# https://askubuntu.com/questions/382750/how-to-save-scrollback-history-in-byobu
export EDITOR='vim'

參考資料

本文由Ubuntu問答整理, 博文地址: https://ubuntuqa.com/zh-tw/article/13467.html,未經允許,請勿轉載。