info-cvs
[Top][All Lists]
Advanced

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

Re: Finding Binary Files


From: Derek R. Price
Subject: Re: Finding Binary Files
Date: Tue, 31 Oct 2000 10:31:53 -0500

Manish Koolwal wrote:

>   From among a group of files, how can we find out which are Binary files?
> (This is in reference to UNIX). Also, please help me if you know any fast
> method to sagregate Binary Files.

UNIX itself rarely makes a distinction.  Some applications (like diff) make
guesses based on the presence/proportion of NUL bytes & other special
characters.

If you have Perl installed, you could use its binary file test operator which
will return true if the first block of the file contains >30% "special"
characters:

    perl -e 'exit(!(-f file && -B $ARGV[0]))' <filename>

will return a Bourne shell true value if the file exists and is binary.  So
in Bourne form:

    #!/bin/sh
    for file in "$@"; do
        if perl -e 'exit(!(-f file && -B $ARGV[0]))' "$file"; then
            # do what I do to binary files
        fi
    done

Derek

--
Derek Price                      CVS Solutions Architect ( http://CVSHome.org )
mailto:address@hidden     OpenAvenue ( http://OpenAvenue.com )
--
I used to think people were crazy to get tattoos.  Nowadays, I envy
them that clarity of thought.  There was at least one point in their lives
when they thought they knew what they were doing.  They could walk into a
tattoo parlor and say, "I want a big old pig, in red and black, with flames
shooting out of its rear!  And I want it right there!  That's who I am!"






reply via email to

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