只提取分隔符"/"之前的部分文本?



我需要找到文件夹中所有文件的所有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

但是我可以从这些输出中获取提取的信息,例如仅htmlmswordpng.

html
msword
msword

是否有任何库可以用来了解文件的详细信息,其中应包括 mime 类型、大小、文件内的字符串和任何其他行为信息。任何建议都会有所帮助。

这样做:

find . -type f -print0 | xargs -0L1 file -b --mime-type | cut -d/ -f2

for方法更快、更安全。(显然,.替换为要从中开始搜索的路径。

最新更新