`find-dired' function question (find file of type x?)

`find-dired' function question (find file of type x?)

Post by Matthew Monacell » Tue, 17 Mar 1998 04:00:00



I don't know if this question should be directed to people who specialize
in unix commands or emacs commands, but I will try this first.

I would like to `M-x find-dired' only text files.  After looking in the
man pages for the find command, I found that I could use `-type f' to list
only the `regular files.'  I assumed that this was a regular ascii file,
but the results showed binary files as well.  

What is a `regular' file?  How can I perform a ascii text file search
using Dired?

Thanks,
Taylor.

 
 
 

`find-dired' function question (find file of type x?)

Post by Kai Grossjohan » Wed, 18 Mar 1998 04:00:00


Quote:>>>>> On Mon, 16 Mar 1998, Matthew Monacelli said:

  Matthew> I would like to `M-x find-dired' only text files.  After
  Matthew> looking in the man pages for the find command, I found that
  Matthew> I could use `-type f' to list only the `regular files.'  I
  Matthew> assumed that this was a regular ascii file, but the results
  Matthew> showed binary files as well.

Unix does not know about text and binary files.  A few commands have
their own heuristic (less, for instance, assumes it's a binary file if
more than a certain percentage of unprintable ASCII or eight-bit
characters appears in a file).

There is a command `file' which knows about some kinds of files.
Sometimes this command thinks the file is an ascii file.  Hm.  I think
the following might give you a list of `ascii files' on stdout.  What
you do with that list of file names is up to you:

  find DIR -type f -print | xargs file | grep ascii | cut -d: -f1

hth.
kai
--
Really cancel?   [OK]  [Cancel]

 
 
 

`find-dired' function question (find file of type x?)

Post by Oleg Goldshmid » Wed, 18 Mar 1998 04:00:00



> There is a command `file' which knows about some kinds of files.
> Sometimes this command thinks the file is an ascii file.  Hm.  I think
> the following might give you a list of `ascii files' on stdout.  What
> you do with that list of file names is up to you:

>   find DIR -type f -print | xargs file | grep ascii | cut -d: -f1

Grepping for "ascii" does not seem to me nearly enough. In fact,
"text" is probably a better choice, if you believe the following
snippet from "man file":

       The  type  printed  will  usually contain one of the words
       text (the file contains only ASCII characters and is prob-
       ably  safe  to read on an ASCII terminal), executable (the
       file contains the result of compiling a program in a  form
       understandable  to  some  UNIX kernel or another), or data
       meaning anything else (data is usually  'binary'  or  non-
       printable).   Exceptions are well-known file formats (core
       files, tar archives) that  are  known  to  contain  binary
       data.   When modifying the file /usr/lib/magic or the pro-
       gram itself, preserve these keywords .  People  depend  on
       knowing  that  all  the readable files in a directory have
       the word ''text'' printed.  Don't do  as  Berkeley  did  -
       change ''shell commands text'' to ''shell script''.

Hmm, this is on the verge of becoming really off-topic - sorry.

--
Oleg Goldshmidt                
BFM Financial Research Ltd.