在linux中使用文件管理器模块检测文件类型



是否有办法从文件管理器中提取bash或python文件描述(例如lubuntu中的PCManFM或任何其他类似nautilus),因为当我使用命令"find"或python-magic pkg或filemagic pkg时,我没有得到像文件管理器那样准确的结果?(例如,当文件包含gif标题和php代码时,只有文件管理器将该文件识别为php脚本,其他文件识别为gif图像)

发现mimetypes是一个不错的选择。Nautilus在/usr/share/mime/中使用它的数据库,python-magic和filemagic使用libmagic, find使用其他东西,我猜

使用linux file命令。我假设文件管理器也这样做(但我不是100%确定)。

例子:

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, stripped

最新更新