Linux cat command to read the content of binary or pdf file
So I tried to read the content of a file with cat command. But the output was gibberish as the file was a binary file, and that I can understand. But the output was very different from what I see on other files. See thephoto. What you don't see is my command cat filename.extensionthen the gibberish output came out, it seems that the file ended but continued again(I did nothing other than enter the first command).
So what is happening? (Please don't tell me I should use strings command)
1 Answer
the file ended but continued again
Some bytes in the gibberish data were interpreted as control sequences. See ANSI escape code:
Certain sequences of bytes, most starting with Esc and
[, are embedded into the text, which the terminal looks for and interprets as commands, not as character codes.
In effect at some point your cursor moved up without clearing the screen, few more lines were printed and the command prompt appeared over the old output.
Some aftermath may be semi-permanent. Please read Weird characters appearing in the console and my answer there.
1