[File] "file" as a type filter

raf file at raf.org
Sun Jun 21 21:28:25 EDT 2026


Hi Gordon,

[Disclaimer] I wrote a file-finding program called
rawhide (rh). It's like find but more fun to use, and
it supports more search criteria, including using
file's libmagic internally for searching by mimetype
and file type descriptions.

It can do what you want. You could put file types and
mime types on the command line, but it would be
prettier if you defined functions (in a config file)
that perform a file/mime type test and then called them
on the command line. It can all be done on the command
line, it's just a longer command.

For example, you could define functions in a ~/.rhrc
file like this:

  exe { f && "application/x-*executable*".mime }

or:

  elf { f && "*ELF *-bit LSB executable*".what }

The "f" is just to avoid using libmagic on things that
aren't regular files. It's not required. The .mime and
.what do glob matches on the mimetype and the file type
description. regex is also possible (with .remime and
.rewhat).

Then you could search for them with:

  rh -e exe

or:

  rh -e elf

Without the functions it would be:

  rh -e 'f && "application/x-*executable*".mime'

or:

  rh -e 'f && "*ELF *-bit LSB executable*".what'

You could even just do:

  rh -e '"*ELF*".what'

Actually, that matches .o files as well, but that's
probably a good thing.

It's at:

  raf.org/rawhide (last released version 3.3)
  github.com/raforg/rawhide
  codeberg.com/raforg/rawhide

The version in github/codeberg has a lot more in it
than the last released version, including {} syntax for
string literals (in addition to the "" syntax), which
makes for nicer commands (especially for shell escapes).
The example above could become:

  rh -e {*ELF*}.what

or even just:

  rh -e {*ELF*}.w

I'm close to releasing the next version (4.0).

Actually, I just noticed the requirement to accept file names
on stdin. rh can't do that. You'd need to use xargs as well:

  xargs rh -e '"*ELF*".what'

cheers,
raf

On Sat, Jun 20, 2026 at 10:37:55AM -0700, Gordon Messmer <gordon.messmer at gmail.com> wrote:

> I've recently discovered executable binaries in source archives while
> building Fedora packages, and I'd like to extend the standard tooling to
> detect and remove content that is not allowed by policy.
> 
> Naturally, "file" seems like the tool best suited to identifying file
> content so that we can strip out what isn't wanted. But file's output types
> are both hard to parse reliably.
> 
> What I would really like is a tool that accepted file types (or MIME types)
> as command line arguments, and which accepted a list of files on stdin and
> provided a list of files that match one of the types on stdout. Something
> that could be used as a filter.
> 
> Would you accept a patch that added functionality like that to the "file"
> command? Or would you accept one that added a new "file-filter" binary?

> -- 
> File mailing list
> File at astron.com
> https://mailman.astron.com/mailman/listinfo/file



More information about the File mailing list