有没有办法从文件管理器中提取bash或python文件描述(例如:因为当我使用命令“PCManFM”或者python-magic或者filemagic时,我不能像在文件管理器中那样得到准确的结果?(例如:当文件包含gif头和php代码时,只有文件管理器将该文件识别为PHP脚本,其他文件识别为gif图像)
发布于 2013-05-06 22:05:48
发现mimetypes是不错的选择。Nautilus在/usr/share/mime/中使用它的数据库,python-magic和filemagic使用libmagic,find使用其他我猜的东西。
发布于 2013-05-05 18:13:19
使用linux file命令。我假设文件管理器也会做同样的事情(但我不是百分之百确定)。
示例:
file test.php
# output: test.php: PHP script, ASCII text
file test.gif
# output: test.gif: GIF image data, version 89a, 32 x 32
file /bin/ls
# output: /bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x37cdd635587f519989044055623abff939002027, strippedhttps://stackoverflow.com/questions/16383462
复制相似问题