[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Finding Binary Files
From: |
Jon Wilson |
Subject: |
Re: Finding Binary Files |
Date: |
Tue, 31 Oct 2000 16:44:47 +0000 (GMT) |
If you don't have or don't want Perl (why? :-0) then you could probably
monkey up a shell script using the Unix 'file' command. Have a look at
'man file' to see exactly how your local version works, but you should be
able to easily tell whether a file is one of 'text', 'executable' or
'data'.
On Tue, 31 Oct 2000, Derek R. Price wrote:
> 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
--
Jon Wilson address@hidden
Dept. of Mathematical Sciences http://www.bath.ac.uk/~mapjpw
University of Bath, UK Tel. (07776) 137939
"Beware of all enterprises that require new clothes." - Thoreau