Bug 2053589

Summary: RFE: add mode where file checks whether the file is of a specified type
Product: [Fedora] Fedora Reporter: Zbigniew Jędrzejewski-Szmek <zbyszek>
Component: fileAssignee: Vincent Mihalkovič <vmihalko>
Status: ASSIGNED --- QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: jkaluza, kdudka, odubaj, svashisht, vmihalko
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Zbigniew Jędrzejewski-Szmek 2022-02-11 14:56:56 UTC
Description of problem:
It'd be great if file could be used to check if file matches a specific file output pattern.
Instead of doing 'file foo | grep -q "ELF"', you could do 'file --check="ELF" foo' and
file would return either 0 or 1 depending on whether it's identification matches.

That would allow file to be used to find files of a certain type, which
is occasionally needed and users ask about [1]:

  find -exec file --check="LSB pie executable" {} \;

would print all "LSB pie executable" matches. The argument would preferably be
an pcre regexp, or a glob pattern.

It would also be useful to do checks, e.g. 'file --check=stripped %{buildroot}/usr/bin/foo'.

[1] https://unix.stackexchange.com/questions/483871/how-to-find-files-by-file-type

Comment 1 Vincent Mihalkovič 2022-02-17 09:26:34 UTC
Interesting idea, I will try to implement this in (near) future.