Existing command line text on screen to file? (non-graphical Linux)

Did you consider the screendump command?


If you can use tmux or screen, they have the ability to save the scrollback buffer to a file.

  • Write all tmux scrollback to a file
  • Copying GNU screen scrollback buffer to file (extended hardcopy)?

Unlike screendump, which is Linux-only, tmux and screen are available for BSD-based OSes too (e.g. macOS, FreeBSD) and won't require special permissions.


You can use script for this. It will record a typescript of the terminal session. By default, it will write to ./typescript. Of course, you need to do this in advance so it is not really a "screenshot".

$ script
Script started, file is typescript
$ ls asdf
ls: cannot access asdf: No such file or directory
$ exit
Script done, file is typescript

# Then check the recordings:

$ cat typescript
Script started on Thu 29 Nov 2018 02:52:04 PM CET

$ ls asdf
ls: cannot access asf: No such file or directory
$ exit

Script done on Thu 29 Nov 2018 02:52:09 PM CET