我需要找到文件夹中所有文件的所有mime类型。我写了这样的小片段。
for i in $(find /home/someFolder -type f);do file -b $i --mime-type;done
这将返回以下输出。
text/html
application/msword
application/msword
text/html
text/html
text/html
application/msword
application/vnd.ms-excel
但是我可以从这些输出中获取提取的信息,例如仅html
或msword
或png
.
html
msword
msword
是否有任何库可以用来了解文件的详细信息,其中应包括 mime 类型、大小、文件内的字符串和任何其他行为信息。任何建议都会有所帮助。
这样做:
find . -type f -print0 | xargs -0L1 file -b --mime-type | cut -d/ -f2
比for
方法更快、更安全。(显然,.
替换为要从中开始搜索的路径。