如何使file命令使用update-mime-database命令生成的magic文件
我使用的是 Ubuntu 服务器 11.10。
我的问题是 file
命令检测到应将 video/mp2t
mime 类型设置为 application/octet-stream
的文件,
所以这里是我做了什么:
我确保
/usr/share/mime/packages/freedesktop.org.xml
包含正确的mp2t描述。我运行了
update-mime-database
命令,该命令除其他外还创建了一个新的 magic 文件:/usr/share/mime/magic
。我发现在运行
file -v
时,它说它正在使用/etc/magic:/usr/share/misc/magic
作为魔法文件。< /p>所以,我告诉
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:
I made sure that
/usr/share/mime/packages/freedesktop.org.xml
contained the correct mp2t description.I ran the
update-mime-database
command that, among other things, created a new magic file:/usr/share/mime/magic
.I discovered that when running
file -v
, it says that it is using/etc/magic:/usr/share/misc/magic
as magic files.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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用共享 MIME 类型数据库似乎是错误的方法。事实上,看起来共享 MIME 数据库和
file
命令使用单独的数据库(具有不同的格式)。由于
file
命令版本太旧,未报告 MIME 类型video/mp2t
。Ubuntu 11.10。附带版本 5.04 的
file
命令。这无法报告video/mp2t
类型。这就是我解决问题的方法:
我下载了较新版本的 libmagic1 deb 包。这个版本是 5.09-2。
我安装了:
问题解决了!
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 thefile
command.Ubuntu 11.10. comes with version 5.04 of the
file
command. This is unable to report thevideo/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:
Problem solved!