Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I write all the scrollback in a tmux session to a file?

capture-panel can grab the current screen, but not the entire scrollback.

share|improve this question

4 Answers 4

up vote 14 down vote accepted

This depends on the value of history-limit that you have set in your .tmux.conf - the default is 2000; if you wish to capture more, you will need to explicitly set the number of lines.

To capture the entire scrollback, enter copy mode, select the entire scrollback, and yank it into the buffer, then paste it into your file.

How you accomplish this will depend on the mode-keys option you prefer, vi or emacs. man tmux has a helpful table describing the respective keys.

I have the following in my .tmux.conf to simplify this:

unbind [
bind Escape copy-mode
unbind p
bind p paste-buffer
bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'y' copy-selection

The process for capturing the full scrollback is then:

PrefixEsc : to enter copy mode

v : to begin visual selection (assuming you are already at the bottom of the screen)

gg : to capture everything in the scrollback

y : to yank it into the buffer

Prefixc : open another tmux window

vim scrollback.txt

i : enter insert mode in vim

Prefixp : paste into file

There is also an answer here describing how to copy the buffer to a temporary file using xsel that might be useful.

share|improve this answer

Here's a tmux plugin that enables this:

https://github.com/tmux-plugins/tmux-logging

After you install it, save the entire scrollback with prefix + alt-shift-p.

share|improve this answer

I had standard key bindings which appeared to be a bit different than in @jasonwryan's answer and didn't change anything in config.

Below is recipe that worked for me. Maybe you will find it useful if you don't want to make any changes in tmux config and just want to quickly copy some of the scrollback.

Prefix == Ctrl+b in my tmux (tmux 1.6, debian 7).

  1. Enter select mode: Prefix + [.
  2. Start selection: Space.
  3. Highlight necessary text using vim navigation (for instance, use arrow keys or press gg to reach beginning of output history).
  4. Actually copy in internal clipboard using Enter. You will be exited from copy mode.
  5. Open any file using vim (probably on new tmux tab) and paste content you copied before using Prefix + ].
  6. Then you may do cat of that file or use output how you need.
share|improve this answer

With tmux 1.5, the capture-pane command accepts -S and -E to specify the start and end lines of the capture; negative values can be used to specify lines from the history. Once you have the data in a buffer, you can save it with save-buffer.

Here is an example binding (suitable for .tmux.conf) that wraps it all up with a prompt for the filename:

bind-key P command-prompt -p 'save history to filename:' -I '~/tmux.history' 'capture-pane -S -32768 ; save-buffer %1 ; delete-buffer'

This captures (up to) 32768 lines of history plus the currently displayed lines. Starting with tmux 1.6, you can use numbers down to INT_MIN if your pane has a history that is deeper than 32Ki lines (usually up to 2Gi lines).


Note: The number of lines in the saved file will not always be equal to the pane’s history limit plus its height.

When a pane’s history buffer is full, tmux discards the oldest 10% of the lines instead of discarding just one line. This means a pane’s effective history depth will sometimes be as low as 90% of its configured limit.

share|improve this answer
    
Thanks for the answer… But my version of tmux doesn't accept -S to capture-pane (it appears to be 1.3-2, although that's from dpkg, as I can't figure out how to get tmux to show me a version number…) –  David Wolever Dec 12 '11 at 5:40
    
You probably are running tmux 1.3; you can probably use tmux server-info | head -1 to see your version. tmux -V works in tmux* 1.4 and later. –  Chris Johnsen Dec 12 '11 at 8:03
    
This is by far one of the most useful tmux commands I have found. –  kenny Jul 19 '12 at 19:03
    
And if you are already in your tmux window and don't want to restart just do a [PrefixKey] : to get to the tmux command line, and then paste the whole line, then you just do a [Prefix] P it is capital P and you are good to go. –  Ali Dec 17 '13 at 21:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.