您是否可以提出任何所需的文件扩展名(对于 Unix、Linux、Windows)?

Dar*_*lar 6 file-format file-extension

我想创建一个仅包含文本的名为“消息”的文件。如果我决定调用它,系统如何知道使用什么程序来读取它:

  • 消息.txt?
  • 消息.dat?
  • 消息.enc?
  • 消息.cpz?
  • 消息.asdfasdf?
  • message.abcdefghijklmnopqrstuvwxyz?
  • message.this_is_so_random?
  • 或者只是没有扩展名的“消息”?

我想知道这适用于纯文本文件,但是包含视频和音频的文件呢?

小智 7

Linux (/Ubuntu) 不像 Windows 那样依赖于文件扩展名。每个文件内部都有一个部分,它可以在其中标识自己的身份。为了显示随机文件是什么,我们有命令file. 一些随机示例:

$ file *
Aptana Studio 3:       directory
Create ubuntu live cd: ASCII English text, with very long lines
1.txt:      empty
gedit_open: Bourne-Again shell script text executable
Run Code Online (Sandbox Code Playgroud)

您还可以mimetype从命令行找到:

$ file --mime-type -b 1.txt 
application/x-empty
$ file --mime-type -b gedit_open 
text/x-shellscript
Run Code Online (Sandbox Code Playgroud)

我们确实有一个~/.local/share/applications/mimeapps.list 您可以将程序关联到扩展的地方。您可以在使用 Nautilus 或使用命令行时使用文件open with内部设置这些内容properties(请参阅https://askubuntu.com/questions/46020/how-to-add-a-mime-type-with-a-project - 快速创建)

所以基本上你可以用文件名做任何你想做的事情,但我建议使用.conf它,如果它包含配置设置,但这只是为了human理解。由于您通常需要execute一个文件才能将其与为此 mimetype 设置的程序相关联,并且您通常将权限设置为不可执行,因此这不是问题。