如何使file命令使用update-mime-database命令生成的magic文件

发布于 2025-01-02 20:25:50 字数 1389 浏览 4 评论 0原文

我使用的是 Ubuntu 服务器 11.10。

我的问题是 file 命令检测到应将 video/mp2t mime 类型设置为 application/octet-stream 的文件,

所以这里是我做了什么:

  1. 我确保/usr/share/mime/packages/freedesktop.org.xml包含正确的mp2t描述。

  2. 我运行了 update-mime-database 命令,该命令除其他外还创建了一个新的 magic 文件:/usr/share/mime/magic

  3. 我发现在运行file -v时,它说它正在使用/etc/magic:/usr/share/misc/magic作为魔法文件。< /p>

  4. 所以,我告诉 file 命令使用我的新魔法文件: file -m /usr/share/mime/magic MY_VIDEOFILE

这就是问题开始的地方。当使用新的 magic 文件运行 file 命令时,我得到以下输出:

/usr/share/mime/magic, 1: Warning: offset `MIME-Magic' invalid
/usr/share/mime/magic, 1: Warning: type `MIME-Magic' invalid
/usr/share/mime/magic, 2: Warning: offset `[90:application/docbook+xml]' invalid
/usr/share/mime/magic, 2: Warning: type `[90:application/docbook+xml]' invalid
  .
  . (921 lines removed from the output)
  .
/usr/share/mime/magic, 1173: Warning: offset `[10:text/x-tex]' invalid
/usr/share/mime/magic, 1173: Warning: type `[10:text/x-tex]' invalid
file: No current entry for continuation

看起来 file 命令需要的 magic 文件格式与 magic 文件的格式不同update-mime-database 输出的文件。

我在这里错过了什么?

如何使 file 命令接受新的 mime 类型?

I am using Ubuntu Server 11.10.

My problem is that the file command detects files that should have had the video/mp2t mime-type as application/octet-stream

So here is what I did:

  1. I made sure that /usr/share/mime/packages/freedesktop.org.xml contained the correct mp2t description.

  2. I ran the update-mime-database command that, among other things, created a new magic file: /usr/share/mime/magic.

  3. I discovered that when running file -v, it says that it is using /etc/magic:/usr/share/misc/magic as magic files.

  4. So, I told the file command to use my new magic file: file -m /usr/share/mime/magic MY_VIDEOFILE

Here is where the problem starts. When running the file command with my new magic file, I get the following output:

/usr/share/mime/magic, 1: Warning: offset `MIME-Magic' invalid
/usr/share/mime/magic, 1: Warning: type `MIME-Magic' invalid
/usr/share/mime/magic, 2: Warning: offset `[90:application/docbook+xml]' invalid
/usr/share/mime/magic, 2: Warning: type `[90:application/docbook+xml]' invalid
  .
  . (921 lines removed from the output)
  .
/usr/share/mime/magic, 1173: Warning: offset `[10:text/x-tex]' invalid
/usr/share/mime/magic, 1173: Warning: type `[10:text/x-tex]' invalid
file: No current entry for continuation

It looks like the file command expects magic files in a different format than the format of the magic files that update-mime-database outputs.

What have I missed here?

How can I make the file command accept new mime types?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗喜 2025-01-09 20:25:50

使用共享 MIME 类型数据库似乎是错误的方法。事实上,看起来共享 MIME 数据库和 file 命令使用单独的数据库(具有不同的格式)。

由于 file 命令版本太旧,未报告 MIME 类型 video/mp2t

Ubuntu 11.10。附带版本 5.04 的 file 命令。这无法报告 video/mp2t 类型。

这就是我解决问题的方法:

我下载了较新版本的 libmagic1 deb 包。这个版本是 5.09-2。

我安装了:

sudo dpkg -i libmagic1_5.09-2_amd64.deb

问题解决了!

$ file MY_VIDEO_FILE --mime-type
MY_VIDEO_FILE: video/mp2t

Using the shared MIME type database seemed to be the wrong approach. In fact, it looks like the shared MIME database and the file command use seperate databases (with different formats).

The MIME type video/mp2t was not reported because of a too old version of the file command.

Ubuntu 11.10. comes with version 5.04 of the file command. This is unable to report the video/mp2t type.

This is what I did to solve the problem:

I downloaded a newer version of the libmagic1 deb package. This one has version 5.09-2.

I installed it:

sudo dpkg -i libmagic1_5.09-2_amd64.deb

Problem solved!

$ file MY_VIDEO_FILE --mime-type
MY_VIDEO_FILE: video/mp2t
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文