System Administration
Showing results for 
Search instead for 
Did you mean: 

finding the ascii and binary files

Go to solution
T G Manikandan
Honored Contributor

finding the ascii and binary files

Is there a better way to find the ascii and binary files from a specified file list.

I am using

$find ./ -type f -exec file {} \;|egrep -i 'ascii|text'

H.Merijn Brand (procura
Honored Contributor

Re: finding the ascii and binary files

If you don't have to deal with thousands and thousands of files, use xargs

Also remember that your command sequence will also show non-(ascii|text) files

lt09:/tmp 124 > cc -o textascii newer.c
lt09:/tmp 125 > file textascii
textascii: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), not stripped
lt09:/tmp 126 >

So a little bit safer and faster:

# find . -type f | xargs file | grep -i -w -e ascii -e text

The perl way would be something like

# perl -MFile::Find -le'find(sub{-T$_&&print$File::Find::name},".")'

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn