管道查找到`file`(命令)linux命令递归

1N5*_*818 4 linux bash recursion file

我有一个文件系统,看起来像这样,文件类型未知。

??? 63206
    ??? 4443606
        ??? 6433
        ??? 712861
        ??? 726355
        ??? 723714
Run Code Online (Sandbox Code Playgroud)

对于每个文件,我可以做file <filename>并获得有关其尺寸的规范。

6433: PNG image data, 138 x 209, 8-bit/color RGBA, non-interlaced

有人能告诉我如何递归地进行管道传输,以便我可以为 bash 中的每个文件路径获得这样的输出吗?

我试过类似的东西find | file。我对管道 bash 并不熟悉。

kar*_*kfa 5

您可能想要添加其他条件,但基本上是从顶级目录

find -type f -exec file {} \;
Run Code Online (Sandbox Code Playgroud)

或者

find path_to_dir -type f -exec file {} \;
Run Code Online (Sandbox Code Playgroud)

  • 我会考虑`-exec file -- {} +`; 这样我们就不会多次调用`file`,并且可以处理文件名(带路径)以破折号开头的情况。 (2认同)