bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cat binary files bug


From: Bob Proulx
Subject: Re: cat binary files bug
Date: Wed, 6 Jun 2007 16:13:03 -0600
User-agent: Mutt/1.5.9i

Alexander Meyr wrote:
> dont know if its a known bug. ill try to describe:

Thanks for the report however what you are describing is not a bug in
the 'cat' program but a misuse of it.

> using backtrack v2 final kernel 2.6.20

This behavior is not related to the kernel.  It is related to the
terminal being used however.

> problem using cat when input is a executive file like /bin/ls. cat displays
> the file and when finished the shell is shown in unreadable characters.

The 'cat' program concatenates files on input and writes the contents
to the output.  It is *not* intended as a binary file viewer.  Doing
so is a misuse of the program and the cause of your problem.  By
writing the binary file contents to your terminal you will almost
certainly cause it to do strange things.

Terminals interpret characters written to them and perform the
required terminal control operation.  Binary input such as from
executables written to the terminal will often randomly hit upon
terminal control sequences that place the terminal into particular
states and without the corresponding sequence to return it to normal
function they will be left in an unusable state.  Normal programs
accessing those terminal control sequences will perform the intended
behavior and issue further byte codes to return the terminal to an
expected state.  Disabling terminal control sequences is not possible
becuase then they would not be available to normal programs.

Since the purpose of 'cat' is to concatenate files it must not modify
or filter the files in the process.  What goes in should come out.
The 'cat' program is typically used to assemble parts of files
together.

To browse files you should use a file browser such as 'more', 'less',
'most', or other programs that act as terminal pagers.  For binary
files it may be more useful to use 'od -tx1', 'hexdump', 'xxd' or
other program that converts binary data into text codes and then
piping the output to a pager.

It is historically traditional on Unix-like systems to use cat to
write short text files to the terminal.  However this is done with
full knowledge that it only behaves as desired on short text files
that do not contain terminal control sequences.  If they do then the
user running cat to write the file to the terminal must be prepared to
accept the consequences and be able to reset the terminal if needed.

Hope this helps,
Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]