【问题标题】:Detecting file type in linux using file managers module for detection files?使用文件管理器模块检测Linux中的文件类型以检测文件?
【发布时间】:2013-05-05 10:11:28
【问题描述】:

有没有办法从文件管理器中提取 bash 或 python 文件描述(例如 lubuntu 中的 PCManFM 或任何其他类似 nautilus),因为当我使用命令“find”或 python-magic pkg 或 filemagic pkg 时,我会没有像在文件管理器中那样获得如此准确的结果? (例如,当文件包含gif头及其下的php代码时,只有文件管理器将文件识别为PHP脚本,其他为gif图像)

【问题讨论】:

  • 我知道 python-magic 和 filemagic 使用 libmagic 进行检测。 TrID 也给了我错误的结果。

标签: linux types detection file-management


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    使用 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
    

    【讨论】:

    • 我几乎可以肯定它没有使用 find,因为我在 nautilus 和 PCManFM 中尝试过,它们都正确显示。 find 命令在某些文件上无法正确显示
    • 可能是。能给我举个例子吗? (文件类型:所需的输出)?
    • ofc...pastebin.com/mvBjwD03 这是一个带有 gif 标头的 php 脚本。所需的输出应该是 php 脚本
    • 不是gif吗? (里面有php标签)..我认为这更像是一个功能而不是缺乏功能。但是,我进行了一些调查,但找不到一个库,例如鹦鹉螺正在为此使用。但我确信有可能获得这些信息。需要更多的努力,例如阅读nautilus的源码
    • 好吧,因为我正在尝试检测混淆文件(恶意软件),所以 gif 对我来说不是一个好选择。 tnx 的努力!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-09
    • 2010-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-25
    相关资源
    最近更新 更多