[Top][All Lists]

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

Re: RFE: "-mtype" + -menc

From: Bernhard Voelker
Subject: Re: RFE: "-mtype" + -menc
Date: Wed, 17 Apr 2019 09:09:28 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

On 4/17/19 4:13 AM, L A Walsh wrote:
> Thinking more about the usefulness of the first, though if
> added, adding the 2nd operator would make sense.
> It might be nice if the classification functionality of 'file'
> was more accessible in a find with some type of
> find -mtime -60 -mtype shell
> would find files newer than 60 days and with a
> "--mime-type" with 'shell' in the type
>   (shell scripts seemed to be bunched under 'text/x-shellscript')
> The "-menc" would correspond to file's "-mime-encoding" type.

This RFE is falling into a category where find(1) ought to inspect the
content of the files in the directory hierarchy.

It is already documented [1] that find(1) only works on specifics of files
in the file system (name, size, owner, permissions, etc.), while searching
for content is the domain of grep(1).


IMO starting to add one of such ideas to find(1) would open a can of
worms, like "what are my MP3 files with genre 'bluegrass'?".
Furthermore, there are specialized tools to do that, and it contradicts
the UNIX philosophy to not just use them.  See below.

> Very often I want to search for something but only in my shell or perl
> scripts and likely within the past 'X' months, stringing everything
> together in a pipeline is certainly possible but awkward when
> what I really want to do is search for a string or function name in
> all shell scripts:
> (# has one failure due to spaces in filename)
>> grep -Pil 'trace.*\(\)'  $(filetype shell)
> grep: Quick: No such file or directory
> grep: Launch-order.sh: No such file or directory
> attrSet
> disp_files_w_recursion.sh
> lineln
> masquerade2
> n_unix_epock2date
> tran
> unix_epoch2date

I don't know the tool "filetype", but whatever it is - to handle
file names safely, it should separate the output with a NUL, so
a construct with "|xargs -0 grep ..." could do the job.

A problem is that file(1) does not seem to have an option to
exit 0 or 1 depending on a given type.  So whatever one does,
s/he always has to match the output against the pattern 'shell'.

In the above, I'd let grep(1) run first over all files:

  $ grep -Rlw strace

If you really want to subsequently double-check that the file
is a shell script with file(1), then it's something like:

  $ grep -ZRlw strace . | xargs -0 file | grep shell

(Of course, that also will also find files with 'shell' in their filename).

With find(1), one needs to write a test which determines whether
the current file matches the wanted classification or not:
e.g. do the matching with expr(1):

  $ find -exec sh -c 'expr match "$(file -b "$@")" ".*shell.*" \
                        >/dev/null ' sh '{}' \; -print

... or directly shell's case/in/esac:

  $ find -exec sh -c 'case "$(file -b "$@")" in *shell*) \
                        exit 0; esac; exit 1' sh '{}' \; -print

> -----
> Now if I want to add before a specific date?....ug...I'm not sure
> how'd I'd begin, but it certainly doesn't seem str8 forward.

Adding a date constraint to the above is trivial then.

Have a nice day,

reply via email to

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