LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

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

Rep: Reputation: 206Reputation: 206Reputation: 206
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:
Code:
$ 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 02:51 PM.
 
Old 07-17-2007, 02:57 PM   #2
macemoneta
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: 326Reputation: 326Reputation: 326Reputation: 326
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, 03:10 PM   #3
GregLee
Member
 
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, 03:55 PM   #4
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,393
Blog Entries: 1

Rep: Reputation: 63
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
Code:
cat /bin/vi | strings
or more directly,
Code:
strings /bin/vi
 
  


Reply

Tags
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 04:34 PM
Cat with Binary File? Xaque208 Linux - General 1 12-06-2004 07:59 PM
redirecting stdin and stdout with pipes: convincing apps they're for a terminal? prell Programming 1 09-02-2004 06:38 AM
how to redirect stdout [binary stream] to multiple processes vtaminh Linux - General 2 08-19-2004 01:05 PM
bash: /bin/cat: cannot execute binary file inTUXicated Linux - General 9 08-06-2003 07:56 AM


All times are GMT -5. The time now is 08:53 PM.

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