-   Linux - Software (
-   -   How to record a command line session to a file? (

Telengard 05-19-2011 02:03 PM

How to record a command line session to a file?
I recently borked my video driver with a series of upgrades and found my system booting to the TTY with no access to the desktop, graphical login, or even X. I spent some days troubleshooting the problem and experimenting with possible fixes. I found myself wishing for some way to copy and paste from the TTY, or at least log all input and output to a file.

I have considered that something like this might lead to a solution:


# bash 2>&1 | tee /tty-session.log
I'm not sure it would work as expected, and it doesn't seem very graceful.

Does anyone have nice solution?

T3RM1NVT0R 05-19-2011 02:07 PM

@ Reply
Hi there,

Check out the following links:

Telengard 05-19-2011 04:45 PM

psacct seems a little heavy. I'm not after forensic analysis and accounting.

Suppose in a command line only session (no desktop, no X, just me and TTY1 and bash) I did something like this:


grep -i 'nouveau' /var/log/Xorg.0.log
The command produced a few interesting lines of output, but then I made some configuration changes and rebooted to try something else. Afterward I realize that it would have been nice to refer back to some of those lines as they were before the configuration changes.


sudo find / -name 'nvidia*' -print -delete
The name of each file is printed, and then it is deleted without prompting. After the process completes I realize that 50 or more filenames scrolled off screen and I can't scroll back to read the names of them all.

In Konsole I have tons of scrollback and I can easily copy and paste with my mouse. Not so with the TTY without X.

T3RM1NVT0R 05-19-2011 05:24 PM

@ Reply
Then you can use script command to capture the activities going on, on your terminal. For more info check out this link:

Telengard 05-19-2011 06:07 PM


Originally Posted by T3RM1NVT0R (Post 4361302)
Then you can use script command to capture the activities going on

Hmm ... this is actually quite nice :)


foo$ ls
input-file.txt  timingfile  typescript
foo$ script -t 2> timingfile
Script started, file is typescript
foo$ rm input-file.txt
foo$ exit
Script done, file is typescript
foo$ ls
timingfile  typescript
foo$ scriptreplay timingfile
foo$ rm input-file.txt
foo$ exit

What about copy and paste without X? Does such a thing exist?

T3RM1NVT0R 05-19-2011 06:18 PM

@ Reply
When you say copy and paste I am assuming that you want to copy a particular file or directory or directory with subdirectory to a particular location. If that is the case then you can go with the following commands:

cp -arvp /root/test /tmp

The above command will work on both when test is a file or when test is a directory, this will copy over test file or directory from /root to /tmp. Good thing about using all these switches (-arvp) is that it will copy over hidden files as well.


a=all (including hidden)
p=preserve permissions

Edit: I just realized that you might be pointing to copying and pasting commands as we can do in X console. Well that will not be possible when you are working on CLI without X.

All times are GMT -5. The time now is 03:35 AM.