Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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...)

thanks!

share|improve this question
add comment

4 Answers 4

up vote 3 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
1  
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
add comment

It is possible to increase the scrollback and view it in copy mode http://www.samsarin.com/blog/2007/03/11/gnu-screen-working-with-the-scrollback-buffer/

share|improve this answer
add comment

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
add comment

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
add comment

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.