cat
doesn't modify the data. There might be old Unix systems where it truncates lines that contain null bytes, but not Linux, and I think not any modern unix-like system.
On the other hand, if you try to display binary data directly on your terminal, the terminal will interpret control characters as commands to control the display. That's what control characters are for. If you want to see a printable representation of the raw data, you have several solutions:
- Run
cat -A
, which will print a readable but ambiguous representation of control characters (e.g. ^A
could be the byte 0x01 or the two-byte sequence 0x5e 0x41).
- Run
hexdump -C
, od -t x1
or some other hexadecimal dump program (or an octal dump if you prefer).
- Run
less /dev/ttyS0
and press F
to read some data then Ctrl+C
to browse it. Inside less, type -r
to toggle between raw display of control characters and a printable representation.
Note that reading /dev/ttyS0
shows what your serial port receives, not what is sent through it. If you want that, spy on the application that's writing, e.g. with strace
or a debugger.