Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 07-17-2007, 03:50 PM   #1
Senior Member
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 210Reputation: 210Reputation: 210
cat on binary: garbles stdout chars, wastes terminal

This is more of an "I'm curious why" question... in regards to a command like this:
$ cat /bin/vi
Strange things happen. The console prompt becomes garbled nonsense. This phenomenon is not unique to vi, either; many binaries have this effect on standard out when cat'ed.

Why does this happen - are bits of the binary being executed? But if this is so, why is the file not executed properly? Lastly, is there anyway to safeguard the cat command from this sort of thing?

Last edited by jhwilliams; 07-17-2007 at 03:51 PM.
Old 07-17-2007, 03:57 PM   #2
Senior Member
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
Terminal programs emulate real hardware, like vt100 (which was an actual device) and xterms. These devices respond to control characters - binary values that do not represent alphanumeric characters - by performing special functions. This is what causes the result you see.

You can usually correct the problem by running the command 'reset' (even if you can't see what you are typing, just type it and hit enter).

There is no need to 'safeguard' the cat command, as no damage is done. Rather than directly using cat on binaries, you probably want to use strings to extract human readable information:

cat /bin/vi | strings | less

You can determine the type of file by using the file command:

file /bin/vi
Old 07-17-2007, 04:10 PM   #3
Registered: Feb 2004
Location: Waimanalo, HI
Distribution: Slackware 10, Fedora 6
Posts: 308

Rep: Reputation: 30
Also, you can "vi /bin/vi" to look inside (if "vi" is vim, anyway).
Old 07-17-2007, 04:55 PM   #4
Senior Member
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,402
Blog Entries: 1

Rep: Reputation: 65
you can filter out binary values without a character representation and display only the strings.
This is nice to find hidden strings in the binary program
cat /bin/vi | strings
or more directly,
strings /bin/vi


binary, cat, stdout

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script - stdout & stderr to terminal and file jantman Linux - Software 1 12-07-2006 05:34 PM
Cat with Binary File? Xaque208 Linux - General 1 12-06-2004 08:59 PM
redirecting stdin and stdout with pipes: convincing apps they're for a terminal? prell Programming 1 09-02-2004 07:38 AM
how to redirect stdout [binary stream] to multiple processes vtaminh Linux - General 2 08-19-2004 02:05 PM
bash: /bin/cat: cannot execute binary file inTUXicated Linux - General 9 08-06-2003 08:56 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:55 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration