Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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've set up .Xresources to be able to print the terminal contents to a file when pressing Alt-P:

XTerm*printAttributes: 2
XTerm*printerCommand: cat - > "`mktemp --tmpdir xterm-screenshot.bin.XXXXXXXXXX`"
XTerm.VT100.translations: #override Meta <KeyPress> P: print() \n

This seems to work fine, except that each line in the output is prefixed by some escape characters and the literal #5. Compare the output at the start of the xterm session:


Is that ESC#5ESC[0m bit at the start normal?

less /tmp/xterm-screenshot.bin.*:

ESC#5ESC[0m$ ESC[0m

less -R /tmp/xterm-screenshot.bin.*:


Additional info:

$ xterm -version
$ uname -a
Linux user 3.2.0-27-generic #43-Ubuntu SMP Fri Jul 6 14:46:35 UTC 2012 i686 i686 i386 GNU/Linux
share|improve this question
up vote 3 down vote accepted

Yes, since you specifically requested xTerm to print() with all the attributes:

XTerm*printAttributes: 2

i.e. the output file contains the whole sequence of bytes sent to xTerm and then you are using less (plain, with no switch) to read the file so you get the text version of what appeared on the terminal (stuff with all kind of attributes). The file in question is:

[me ~]$ file -b /tmp/xterm-screenshot.bin.HBsmSPRrFx
ASCII text, with CRLF line terminators, with escape sequences

You'll have to use -r (--raw-control-chars) with less in order to view the file content the same way it appeared on terminal:

less -r /tmp/xterm-screenshot.bin.HBsmSPRrFx

If you don't want the escape sequences in your output file (that is, you want a plain text file with no graphical attributes) you have to use:

XTerm*printAttributes: 0

in your ~/.Xresources. From xTerm manual:

printAttributes (class PrintAttributes)
    Specifies whether to print graphic attributes along with the text. A real DEC VTxxx terminal
    will print the underline, highlighting codes but your printer may not handle these. A "0"
    disables the attributes. A "1" prints the normal set of attributes (bold, underline, inverse
    and blink) as VT100-style control sequences. A "2" prints ANSI color attributes as well.
share|improve this answer
Ah, I get it - I was using less -R rather than less -r. – l0b0 Oct 2 '12 at 7:09

Your Answer


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.