资讯详情

Linux:桌面系统中的文件后缀和类型

📅 2026/10/27 18:20:12 | 华诺云谱 👁 阅读
Linux:桌面系统中的文件后缀和类型
相关阅读Linuxhttps://blog.csdn.net/weixin_45791458/category_12234591.html?spm1001.2014.3001.5482Linux中的文件后缀与Windows系统有些不同因为其似乎没有很重要一个文件是否可执行对后缀没有要求。但是后缀依然可以用于表示文件类型也可以据此选择不同类型文件的默认打开方式。在Linux系统中MIME多用途互联网邮件扩展文件类型机制是用来识别和处理不同类型文件的一种方式。MIME类型也称为互联网媒体类型最初是为了在电子邮件系统中识别不同格式的文件而设计的但后来被广泛应用于HTTP传输中以及在操作系统如Linux中识别文件格式。MIME类型通常由两部分组成类型(type)和子类型(subtype)用斜线分隔。例如test/html表示HTML文档image/jpeg表示JPEG图像文件。/usr/share/mime目录中有一些XML文件它们是自动生成的在安装或更新shared-mime-info包时由update-mime-database命令更新它们规定了MIME类型、以及文件后缀和文件类型的映射关系。/usr/share/mime目录下的types文件中包括了目前的所有MIME类型如下所示。*********************** text/xmcd video/3gpp video/3gpp2 video/annodex video/dv video/isivideo video/mp2t video/mp4 video/mpeg video/ogg video/quicktime video/vnd.mpegurl video/vnd.rn-realvideo video/vnd.vivo video/wavelet video/webm video/x-anim video/x-flic ***********************下面用/usr/share/mime/text目录下x-python.xml文件进行举例说明。?xml version1.0 encodingutf-8? mime-type xmlnshttp://www.freedesktop.org/standards/shared-mime-info typetext/x-python !--Created automatically by update-mime-database. DO NOT EDIT!-- commentPython script/comment comment xml:langarسكربت بايثون/comment comment xml:langbelatinSkrypt Python/comment comment xml:langbgСкрипт — Python/comment comment xml:langcascript Python/comment comment xml:langcsskript Python/comment comment xml:langdaPythonprogram/comment comment xml:langdePython-Skript/comment comment xml:langelΔέσμη ενεργειών Python/comment comment xml:langen_GBPython script/comment comment xml:langeoPython-skripto/comment comment xml:langessecuencia de órdenes en Python/comment comment xml:langeuPython script-a/comment comment xml:langfiPython-komentotiedosto/comment comment xml:langfoPython boðrøð/comment comment xml:langfrscript Python/comment comment xml:langgascript Python/comment comment xml:langglScript en Python/comment comment xml:langheתסריט Python/comment comment xml:langhrPython skripta/comment comment xml:langhuPython-parancsfájl/comment comment xml:langiaScript Python/comment comment xml:langidSkrip Python/comment comment xml:langitScript Python/comment comment xml:langjaPython スクリプト/comment comment xml:langkkPython сценарийі/comment comment xml:langko파이썬 스크립트/comment comment xml:langltPython scenarijus/comment comment xml:langlvPython skripts/comment comment xml:langmsSkrip Python/comment comment xml:langnbPython-skript/comment comment xml:langnlPython-script/comment comment xml:langnnPython-skript/comment comment xml:langocescript Python/comment comment xml:langplSkrypt Python/comment comment xml:langptscript Python/comment comment xml:langpt_BRScript Python/comment comment xml:langroScript Python/comment comment xml:langruсценарий Python/comment comment xml:langskSkript Python/comment comment xml:langslSkriptna datoteka Python/comment comment xml:langsqScript Python/comment comment xml:langsrПитонова скрипта/comment comment xml:langsvPythonskript/comment comment xml:langtrPython betiği/comment comment xml:langukскрипт мовою Python/comment comment xml:langviVăn lệnh Python/comment comment xml:langzh_CNPython 脚本/comment comment xml:langzh_TWPython 指令稿/comment sub-class-of typeapplication/x-executable/ sub-class-of typetext/plain/ glob pattern*.py/ glob pattern*.pyx/ glob pattern*.wsgi/ /mime-typeXML文件中类似commentPython script/comment的字段规定了在桌面系统下text/x-python类型文件在进行查询时显示的类型。最后的glob pattern*.py/字段规定了哪些后缀的文件会被识别为text/x-python类型不加说明后缀是大小写不敏感的即.py、.PY、.pY和.Py都会被识别为text/x-python类型。下面给出了一个大小写敏感的例子出现在x-csrc.xml中其中的glob pattern*.C case-sensitivetrue/字段说明了只有大写C后缀的文件才会被识别为text/x-csrc类型。?xml version1.0 encodingutf-8? mime-type xmlnshttp://www.freedesktop.org/standards/shared-mime-info typetext/x-csrc !--Created automatically by update-mime-database. DO NOT EDIT!-- commentC source code/comment comment xml:langarشفرة مصدر سي/comment comment xml:langbelatinKryničny kod C/comment comment xml:langbgИзходен код — C/comment comment xml:langcacodi font en C/comment comment xml:langcszdrojový kód C/comment comment xml:langdaC-kildekode/comment comment xml:langdeC-Quelltext/comment comment xml:langelΠηγαίος κώδικας C/comment comment xml:langen_GBC source code/comment comment xml:langeoC-fontkodo/comment comment xml:langescódigo fuente en C/comment comment xml:langeuC iturburu-kodea/comment comment xml:langfiC-lähdekoodi/comment comment xml:langfoC keldukota/comment comment xml:langfrcode source C/comment comment xml:langgacód foinseach C/comment comment xml:langglcódigo fonte de C/comment comment xml:langheקוד מקור של C‎/comment comment xml:langhrC izvorni kod/comment comment xml:langhuC-forráskód/comment comment xml:langiaCodice-fonte C/comment comment xml:langidKode program C/comment comment xml:langitCodice sorgente C/comment comment xml:langjaC ソースコード/comment comment xml:langkaC-ის საწყისი კოდი/comment comment xml:langkkC бастапқы коды/comment comment xml:langkoC 소스 코드/comment comment xml:langltC pradinis kodas/comment comment xml:langlvC pirmkods/comment comment xml:langmsKod sumber C/comment comment xml:langnbC-kildekode/comment comment xml:langnlC-broncode/comment comment xml:langnnC-kjeldekode/comment comment xml:langoccòde font C/comment comment xml:langplKod źródłowy C/comment comment xml:langptcódigo origem C/comment comment xml:langpt_BRCódigo-fonte C/comment comment xml:langroCod sursă C/comment comment xml:langruисходный код C/comment comment xml:langskZdrojový kód jazyka C/comment comment xml:langslDatoteka izvorne kode C/comment comment xml:langsqKod burues C/comment comment xml:langsrЦ изворни ко̂д/comment comment xml:langsvC-källkod/comment comment xml:langtrC kaynak kodu/comment comment xml:langukвихідний код мовою C/comment comment xml:langviMã nguồn C/comment comment xml:langzh_CNC 源代码/comment comment xml:langzh_TWC 源碼/comment sub-class-of typetext/x-csrc/ glob pattern*.cpp/ glob pattern*.cxx/ glob pattern*.cc/ glob pattern*.C case-sensitivetrue/ glob pattern*.c/ /mime-type下图展示了在桌面系统GNOME中一个.py后缀文件的类型查询结果。可以看出首先根据系统语言这里是默认显示了comment字段规定的类型名并且在小括号中显示了MIME类型。不同的桌面系统的显示结果可能有差异下面是桌面系统XFCE中一个.py后缀文件的类型查询结果。其中根据系统语言这里是zh_CN显示了comment字段规定的类型名即Python 脚本。需要注意的是一个有后缀的文件显示出来的类型是由后缀决定的这可能与文件真实类型不符合。如一个可执行二进制文件如果重命名以.py为后缀则其显示出来的类型会是错误的Python 脚本。所以一个文件的后缀只是对其类型的一个暗示但并不确保其准确性。如果要准确识别一个文件的类型可以使用file命令它是通过文件的魔术头识别文件类型的因此更为准确如下所示。$ file test.py test.py: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]8c8cfe14852611f912f695c4ff7fae0b6607382d, not stripped对于没有后缀的文件桌面系统会根据文件内容尝试推断其类型即如果他是一个二进制文件则可能推断为executable (application/x-executable)类型。下面是一个例子展示了一个没有后缀的jupyterjson格式的文件被正确识别为了Jupyter Notebook (application/x-ipynbjson)类型。{ cells: [ { cell_type: markdown, metadata: {}, source: [ # 简单的Jupyter Notebook ] }, { cell_type: code, execution_count: 1, metadata: {}, outputs: [], source: [ print(Hello, world!) ] } ], metadata: { kernelspec: { display_name: Python 3, name: python3 } }, nbformat: 4, nbformat_minor: 2 }
📝

华诺云谱内容团队

资深建站顾问 · 行业研究员

10年+企业数字化服务经验,专注智能建站、SEO优化与品牌营销,持续输出建站技巧、行业洞察与营销干货,已帮助5000+企业实现数字化增长。

你可能需要的服务

订阅华诺云谱资讯周报

每周一封,精选建站技巧、SEO与营销干货,直达邮箱。已有 8,000+ 企业主订阅,助你少走弯路。

↑