Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I used the following command in my unix box.

$ cat ksh

And it gave a rolling log of latin and greek letters and symbols and it kept on going with no signs of stopping. Eventually I had to close my connection tool to stop it.

I was just wondering what was it displaying?

share|improve this question

migrated from stackoverflow.com May 16 '12 at 12:35

This question came from our site for professional and enthusiast programmers.

    
You missed the command! –  Andreas Florath May 11 '12 at 18:27
    
No, he failed at formatting. Fixed that. –  larsks May 11 '12 at 18:29
1  
Dude, that's what happens when you "cat" a binary file :) –  paulsm4 May 11 '12 at 18:29
    
If you're up for a real thrill, try to "type" an .exe in a Windows command prompt. You'll get the Latin and Greek letters, the symbols, and it will even beep at you, too! ;) –  paulsm4 May 11 '12 at 18:31
    
Not sure that this is a programming question; perhaps superuser would make more sense? –  Charles Duffy May 11 '12 at 18:33

3 Answers 3

up vote 4 down vote accepted

If you were running cat on the actual ksh binary file, then you were seeing the raw machine code of the ksh program being interpreted as if it was human-readable text. Of course, it wasn't, so the characters displayed were random characters from your terminal's character set, plus control and other non-printable characters.

Some of the control characters in a binary file can mess up your terminal's state. If you close the connection, that's fine, but you can also recover without closing your connection by pressing control-C to stop the process and then typing "reset" and pressing enter.

share|improve this answer
1  
Addendum: the command hd $(which ksh) | less will display the same data (the contents of the ksh executable) in a format that humans can actually get useful information out of. –  Zack May 11 '12 at 18:32
    
bash: hd: command not found –  Stephen P May 11 '12 at 18:40
    
The bytes of ksh may be seen with od -tx1 ksh. –  eepp May 11 '12 at 18:50
    
On my Linux box (Debian) hd comes from the bsdmainutils package. I don't know where to get it for other distributions. OSX doesn't have hd but it does have hexdump which does something similar (sadly, it lacks the ASCII column which hd provides). –  Zack May 12 '12 at 7:14
    
Vim comes with xxd, and util-linux has hexdump -C. @Zack, does OSX hexdump support -C? –  grawity May 16 '12 at 12:39

That is because you were trying to print the contents of a binary file, have done that a few times before by accident, and it almost always crashes putty, now for some real fun, go ahead and do cat /dev/urandom, always a good time (urandom makes an awesome random data generator for things such as generating passwords, coin flips etc, plus it is "true" random data because this data is pulled from the entropy pool (which is based on things such as electrical noise, etc that the server monitors) )

share|improve this answer

A binary executable is a file like any other; its contents aren't guaranteed to make sense to humans, and usually don't. cat won't stop you from displaying it, because it can't really tell the difference between an executable and (say) a text file with a lot of non-ISO-8859-1 Unicode in it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.