Short answer
- You can almost always assume it's not
cat
's fault; it is too widespread, well-tested and simple to have such big, obvious bugs.
- Don't just
cat
a binary file to your terminal; terminals are designed to show text, not arbitrary binary data.
Long answer
It is not the cat
process itself that gets stuck, but the terminal emulator, i.e. the program displaying the window. cat
itself couldn't care less about what is actually in the file, all it does is copy whatever is in it to its stdout¹. You can (theoretically) cat /dev/sda
and it would happily dump your entire HDD contents onto your terminal.
Terminal emulators are however not designed to show any arbitrary binary data. They are made to show text, and it is possible to control how the text is displayed by embedding special sequences of non-printable characters in them, called control codes or escape codes, as most of them start with the "escape character" (\x1B
, often displayed as ^[
).
Now if you dump binary data onto your terminal, it may see an escape character (or any other character that is special to it), and try to interpret an escape code from it. This means it will not display the following characters, at least until it can decide whether they actually form a valid sequence or not. Another possibility is that there's a valid sequence embedded somewhere that triggers special behaviour, like blanking the terminal (and making it look like nothing was printed at all), or changing the foreground color (and making all subsequent output invisible).
I'll assume that on the two different computers you were testing on, you used different terminal emulators, which would explain the different behaviours you were seeing: not all TEs recognize all escape codes, as some implement private, non-standard sequences for some unique behaviours (like kitty
's raster image displaying protocol).
¹) There are some flags to cat
, such as -t
which was suggested in the comments, that make it manipulate the file contents before outputting them. See man cat
for more info.
What you can do
Sometimes you may want or need to look at the actual bytes within a file. In these situations you should use a specialized software called a hex editor, which displays the hexadecimal representation of each byte in the file, thus making it safe to print on a terminal.
For simple viewing purposes, you can also use the xxd
program, which may be shipped with vim
or standalone (depending on your distribution).
You can extract the various texts that might be present in any binary file by using strings
, which is included in binutils
in most distros. (Thanks to @Rui F Ribeiro for pointing it out)