列出/查找所有子目录中的所有常规文件,不包括二进制文件

Sam*_*una 6 linux find

在 Linux 中。

我知道我可以做find . -type f,但这包括二进制文件,我找不到用 find 排除它们的方法

Den*_*son 7

file /usr/bin/file例如,在我的系统上的输出中不包含“二进制”一词。如果file -i可用,它确实包含“二进制”一词。没有-i,测试“文本”这个词的存在可能更可靠。

find -type f -exec sh -c "file {} | grep text >/dev/null" \; -print
Run Code Online (Sandbox Code Playgroud)

或者

find -type f -exec sh -c "file {} | grep text >/dev/null" \; -ls
Run Code Online (Sandbox Code Playgroud)

使用-i

find -type f -exec sh -c "file -i {} | grep -v binary >/dev/null" \; -print
Run Code Online (Sandbox Code Playgroud)

Usingfile只是一个近似值,因为它使用启发式方法来确定文件的类型,并且没有硬性定义什么构成“二进制”文件。空文件是“二进制文件”吗?file说是。此外,有很多(通常不常见的)方法可以通过file.