36

I've had an interesting terminal session in byobu, and I'd like to save the terminal output (commands and all) to a file - how can I do that?

According to the byobu man page:

Ctrl-a ~ - Save the current window's scrollback buffer

This may indeed be doing something, but I've found no indication of where and under what name it might be saved.

drevicko
  • 4,373

9 Answers9

41

An old question still not workably answered for earlier byobu versions, and I hit the need again.

This time I found a workable solution. From 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. I hit F7 to enter scrollback mode,
  2. Space to start selecting,
  3. gg to scroll to the top of the buffer (thanks @GeorgeMarian)
    • If that doesn't work, try this: either with lots of Page up or : followed by the largest line number (indicated top right) and Page up to get to the top of that page,
  4. Enter to copy (to byobu's clipboard, not a terminal/system one),
  5. then cat > my-byobu-dump.txt in the terminal,
  6. Alt+Insert or ctrl+A,] to paste (again, from byobu's clipboard)
  7. Ctrl+D to close the file.
drevicko
  • 4,373
  • This was the only answer that worked well for me. – pjvandehaar Oct 01 '15 at 15:57
  • 1
    For step 3, if you want to get to the very top use gg (just like vim). – George Marian Jul 27 '17 at 17:32
  • @GeorgeMarian Do you know if that's from a vim-emulation mode? will people find other behaviours? Seems the default behaviour (at least with byobu 5.17 over tmux 1.6) – drevicko Jul 31 '17 at 10:19
  • There's no vim-emulation mode in byobu that I know of. There's vi-like movement commands in scrollback mode, and maybe elsewhere. I just happened to try them, since -- well -- Linux. (I've been using less a lot lately, searching and moving around.) – George Marian Aug 01 '17 at 15:20
  • ok. could it be coming from the underlying multiplex technology (screen or tmux)? Anyway, I've added your suggestion. Many thanks :) – drevicko Aug 02 '17 at 14:24
  • It guess it could be, but I don't know. I don't remember if I used them back when I was using screen before byobu came out. That said, vi-like movement and some other vi-like things are used in a bunch of Linux applications. (e.g. less) You could try switching and see if it makes a difference, but I'd expect byobu to implement the missing functionality if it can. (I.e. tmux back end acting like screen) – George Marian Aug 03 '17 at 06:23
  • @drevicko if you're still having this problem, I wonder if the following solves it for you: https://askubuntu.com/a/948916/269058 – scottkosty Aug 23 '17 at 06:34
  • cat > dump.txt appears to require some magic. cat does not read from the byobu clipboard on my computer – Drew May 20 '19 at 20:01
  • @Drew do you mean alt+insert etc.. does not paste from the byobu clipboard?? cat without arguments copies from stdin to stdout. – drevicko May 24 '19 at 03:08
32

Or, you can simply use Byobu's hotkey for this:

  • Shift-F7

That will take your history and put it into $BYOBU_RUN_DIR/printscreen.

Pablo Bianchi
  • 15,657
  • sift-F7 doesn't appear to do anything and the byobu help screen doesn't mention it either - I'm using byobu 5.17 with tmux 1.6 in ubuntu. – drevicko Jan 26 '15 at 00:41
  • 1
    This is awesome, saved me a lot of time! – Ctrl-C Feb 25 '15 at 12:59
  • 3
    I'm running byobu 5.74 and that option does appear for me in the help screen and works as described. I'd be surprised if that was not the case given that Dustin is the creator of byobu. :) Worth mentioning the output is saved at $BYOBU_RUN_DIR/printscreen (as noted in the help screen). – Chuim Apr 30 '15 at 08:24
  • 3
    For me it was saved to /dev/shm/byobu-serg-ucvwj2rJ/printscreen, where serg is obviously my username – Sergiy Kolodyazhnyy Oct 02 '15 at 04:01
  • 1
    I know this is an old answer. Anyhow, I experience the same issue: the shift-F7 seems not doing anything (even though the shortcut is present in the help menu). I'm using it on a Ubuntu-16.04 host with byobu version 5.106 & tmux 2.1. – Marc Apr 24 '17 at 04:03
  • Shift+F7 was my favorite feature of byobu, recently switched from 14.04 to 16.04, it does NOT work the same, instead of opening vim it just saves it to /dev/shm/byobu-myusername-somerandomword/printscreen – RNA Dec 21 '17 at 06:43
  • This partially worked for me (debian unstable), but the buffer only had about 32k lines out of 94k history. @drevicko's answer below worked perfectly though. – Laurent S Apr 08 '20 at 08:19
4

If you're used not to use the F-keys then this might work for you:

  • Ctrl+a, [: enter the scrollback mode
  • Space enter the copy mode (optional)
  • Enter exit the scrollback or copy mode
  • Ctrl+a, ]: paste what was copied

Where Ctrl+a is your tmux (default Byobu backend) prefix/escape sequence.

Pablo Bianchi
  • 15,657
Ikar Pohorský
  • 318
  • 2
  • 10
3

Shift + F7 only works as expected if you have the EDITOR environment variable set to an editor within byobu. For some reason, in some cases (e.g. for me when connecting through SSH to another computer), setting this variable in ~/.profile is not enough. One place to set it so that byobu always reads it is in ~/.bashrc. Copy something like the following to your ~/.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'
scottkosty
  • 361
  • 2
  • 4
1

If you need to save the history use Shift + F7 shorcut. Like @dustin-kirkland says.

If you prefer to scroll up and down in your terminal, It depends if you use tmux or screen. Examples:

  1. Screeen:

    • CTRL + a: If you use [ then, you enter in scroll mode like @ikar-pohorský says.
  2. Tmux:

    • ALT + PageUp: you scroll up.
    • ALT + PageDown: you scroll down.

Byobu F1 help

mrroot5
  • 559
1

Ctrl+a, ? shows me that capture-pane and save-buffer are the key commands to save scrollback.

bind-key    -T root   S-F7             capture-pane -S -32768 ; save-buffer /dev/shm/byobu-asari-JG2wDS8x/printscreen ; delete-buffer ; new-window -n PRINTSCREEN " /dev/shm/byobu-asari-JG2wDS8x/printscreen"

When Shift+F7 doesn't work for you (e.g. when your terminal software consumes F-key events), try just as help says: Ctrl+a, :, capture-pane -S -32768 ; save-buffer /path/to/printscreen and Enter.

asari
  • 111
1

Use Ctrl+A+~ to copy the scrollback buffer to the byobu clipboard.

Paste the text into an editor using Alt+insert or Ctrl+A+].

(Adjust Ctrl+A if you've changed your escape key.)

snoop
  • 4,040
  • 9
  • 40
  • 58
  • I've only a Mac to work from at the moment, and ctrl-a ~ then ctrl-a ] aren't doing anything - I suspect ctrl-a isn't making it to byobu (which is at the other end of an ssh tunnel).. Any ideas? – drevicko Jul 31 '14 at 13:15
0

Select the text you wish to save, then press Control + Shift + C Next, open your favorite text editor. Then paste the content here using Control + V . Finally save the file in the desired location.

TERMINAL TIP OF THE DAY: When trying to copy something in terminal do it as usual expect use Control + Shift + C instead of Control +C, and paste as usual. For pasting something that is on the clipboard into the terminal use Control + Shift + V.

cubecubed
  • 696
  • its just a simple copy paste scheme, will waste time to copy and then paste . drevicko wants to do it via terminal or automatically saves it somewhere . – Sukupa91 Nov 27 '13 at 03:13
  • Didn't he say I'd like to save everything to a file? This how he do it. – cubecubed Nov 27 '13 at 03:17
  • 1
    No, I believe you'd just get on screen's worth - not the whole (perhaps 10000 line) byobu scrollback history... Note that byobu stores a terminal history that is independent of the terminal app your using. – drevicko Nov 27 '13 at 03:18
  • If you hold the mouse above the window it will scroll up so that you can highlight the entire thing. – cubecubed Nov 27 '13 at 03:20
  • @drevicko we can save output of commands by using ">" like for saving the output for ls we need to use "ls >file" where file is the text file name, can you just relate it to your question. – Sukupa91 Nov 27 '13 at 03:21
  • He doesn't want to save the output of one command. He wishes to save the commands and all of the results. – cubecubed Nov 27 '13 at 03:22
  • He will definitely want it to happen automatically. What you are suggesting, IMHO, is a trivial solution. Just like: "How do I save this picture from the browser?" "Take a screenshot". – SiddharthaRT Nov 27 '13 at 03:43
  • 2
    @Cammy_the_block you're missing the "byobu" bit, look it up (a VERY handy thing if you're working on remote servers). It stores terminal sessions that you can disconnect from and later reconnect to. I have 10,000 lines of terminal history that is NOT accessible to the local terminal application. Byobu (and the backend it's using: tmux or screen) have their own set of keyboard driven commands to access that history. – drevicko Nov 27 '13 at 04:11
  • Is there any reason to keep this post or should I delete it? – cubecubed Nov 27 '13 at 04:20
  • no let it be here , it has discussion bout the question, just remove those pics.. – Sukupa91 Nov 27 '13 at 04:35
0

Ctrl+A+] will work if you type from 1 to 20 times or more with abracodabra. But the only one command will work without headache to paste text from buffer to terminal or file is Alt+Ins. Byobu is GPLv3 software, authored and maintained by Dustin Kirkland.

Pablo Bianchi
  • 15,657
bemonolit
  • 925