Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I like to save everything I do on the command line, for example when I upgrade something and want to read back how the upgrade went etc..

Usually with Mac OSX and Terminal you can scroll back as much as you want, and save with Cmd-S. But when I'm on SSH using gnu screen, then I can't scroll back directly from terminal.

How can I save to disk everything that happens in a screen session? Maybe by default (every session automatically creates a file to disk...)


share|improve this question
up vote 4 down vote accepted

There's a logging feature in screen. Start it when you start screen by doing screen -L (or from within screen). Or, also from within screen, you could press Ctrl-a : H.

If you want to have logging on as the default, add the following line to your ~/.screenrc file:

deflog on

You may want to set the filename using something like:

logfile /tmp/screenlog.%n
share|improve this answer
One should maybe not store it on /tmp, as it usually gets cleaned on reboot (e.g. because of power failure). – maxelost Jan 26 '11 at 11:38
@maxelost: That's something to consider. It was just an example, though. The point was to include an absolute directory since the default behavior is to create the log file in the current directory. Also, screen sessions (even detached ones) do not survive reboot. – Dennis Williamson Jan 26 '11 at 15:51

It is possible to increase the scrollback and view it in copy mode

share|improve this answer

Option 1: Look into the script command. "man script"

"Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr"

Basically type "script" (no quotes) - do your work, and type exit once to end the session.

Option 2: Use screen's "hardcopy" mode. 'Crtl-a' then 'h' This will save the current session to a file.

note: GNU Screen does have the ability to scroll. Use 'crtl-]' (right square bracket) to enter copy mode, then 'ctrl-b' and 'ctrl-f' to move p and down a page at a time.

share|improve this answer

You will want to use the 'log' operation, usually bound to Ctrl-a H. This opens a new file called screenlog.N where N is the window number. If the file exists, then output is appended to the file. All output in that window is logged to the screenlog.N file until you deactivate by pressing Ctrl-a H again. You can also get this functionality with Ctrl-a :log. You can change the name using the logfile {filename} command. The file gets placed in the directory in which screen was first started, but that can be changed with the logfile command or with chdir [{directory}].

Note that this is not the same as hardcopy or the scroll buffer. This is the same functionality as the script(1) program, but tied to a single window and without calling a new program.

If you want to save the entire contents of the scroll buffer, use Ctrl-a ] g <space> G <space> Ctrl-a :writebuf This saves the scroll buffer to the file /tmp/screen-exchange. if you want to save only a portion, then change the 'g' and 'G' to other movement keys.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .