通过grep查找到文件

Find through grep to file

我正在尝试通过 grep 将输出从 find 发送到 file -b 命令,忽略我在正则表达式中定义的特定文件。据我所知,我认为您不能将输出通过管道传输到 file。 您知道如何在不使用任何外部文件的情况下做到这一点吗? 我不需要使用 grep 来忽略文件,但我需要使用指定的正则表达式来忽略实用程序 file 的文件和输出,所以如果有另一个选项我愿意接受。

提前致谢:)

我尝试了什么:

find dir -type f -exec file -b {} \;

这对我有用,但不会忽略任何文件

find dir -type f -exec grep -v 'file.' {} \; -exec file -b {} \;

作为第一个示例工作,但打印出我不需要的文件内容

编辑:我需要忽略文件名和路径,而不是 file

的输出

EDIT2:这是我的文件夹

dir
dir/a
dir/a/b
dir/a/b/c
dir/a/b/c/file
dir/a/b/filec
dir/a/fileb
dir/filea

每个文件都是 ASCII 文本类型,我想要的输出是使用此正则表达式 'file(a|b)' 忽略名为 fileafileb 的文件,但不包括名为 [=17] 的文件=] 和 filec 不适合正则表达式,因此我的命令所需的输出将是

ASCII text
ASCII text

如果我没理解错的话,是这样的:

find dir -type f -exec file {} + | grep -Ev ':\s*ASCII text|empty'

将列出不属于 ASCII textempty 的文件。

如果需要提前grep文件名:

find dir -type f -print | grep -v 'pattern' | file -b -f - 

找到

find dir -type f ! -name 'file[ab]' -exec file -b {} \;

或者只是 bash:

shopt -s globstar
for f in dir/**/file[^ab]; do
    file -b "$f"
done

如果你想忽略一个模式你可以使用!运算符,它会像这样工作:

find -type f ! -name "file[ab]"