![](https://i-blog.csdnimg.cn/blog_migrate/880cb6ad880fa512c6bafe655028e408.png)
A file extension, or filename extension, is a suffix at the end of a computer file. It comes after the period, and is usually two-four characters long. If you’ve ever opened a document or viewed a picture, you’ve probably noticed these letters at the end of your file.
文件扩展名或文件扩展名是计算机文件末尾的后缀。 它在句点之后出现,通常为两到四个字符。 如果您打开过文档或查看过图片,则可能在文件末尾注意到了这些字母。
File extensions are used by the operating system to identify what apps are associated with what file types—in other words, what app opens when you double-click the file. For example, a file named “awesome_picture.jpg” has the “jpg” file extension. When you open that file in Windows, for example, the operating system looks for whatever app is associated with JPG files, opens that app, and loads the file.
操作系统使用文件扩展名来标识哪些应用程序与哪些文件类型相关联,换句话说,双击该文件时将打开什么应用程序。 例如,名为“ awesome_picture.jpg”的文件具有“ jpg”文件扩展名。 例如,当您在Windows中打开该文件时,操作系统将查找与JPG文件关联的任何应用程序,然后打开该应用程序并加载该文件。
有哪些类型的扩展名? (What Types Of Extensions Are There?)
There are many different types of file extensions—way too many to list in an article—but here a few examples of common file extensions you might see floating around on your computer:
文件扩展名有很多不同的类型(在文章中列出的方式太多了),但是在这里,您可能会在计算机上看到一些常见文件扩展名的示例:
DOC/DOCX: A Microsoft Word document. DOC was the original extension used for Word documents, but Microsoft changed the format when Word 2007 debuted. Word documents are now based on the XML format, hence the addition of the “X” at the end of the extension.
DOC / DOCX: Microsoft Word文档。 DOC是用于Word文档的原始扩展名,但是Microsoft在Word 2007首次发布时更改了格式。 Word文档现在基于XML格式,因此在扩展名的末尾添加了“ X”。
XLS/XLSX: – A Microsoft Excel spreadsheet.
XLS / XLSX: – Microsoft Excel电子表格。
PNG: Portable Network Graphics, a lossless image file format.
PNG:可移植网络图形,一种无损的图像文件格式。
HTM/HTML: The HyperText Markup Language format for creating web pages online.
HTM / HTML:用于在线创建网页的超文本标记语言格式。
PDF: The Portable Document Format originated by Adobe, and used to maintain formatting in distributed documents.
PDF:可移植文档格式,由Adobe发起,用于维护分布式文档中的格式。
EXE: An executable format used for programs you can run.
EXE:一种可执行格式,用于可以运行的程序。
And like we said, this is just a smattering of the file extensions out there. There are literally thousands.
就像我们说的,这只是文件扩展名的一小部分。 实际上有数千个。
It’s also important to be aware that there are file types out there that are inherently risky, and could be dangerous. Typically, these are executable files that can run certain types of code when you try to open them. Play it safe and don’t open files unless they come from a trusted source.
同样重要的是要注意那里存在着固有的危险并且可能是危险的文件类型。 通常,这些是可执行文件,当您尝试打开它们时可以运行某些类型的代码。 安全播放,除非文件来自受信任的来源,否则请勿打开文件。
如果看不到文件扩展名怎么办? (What If I Don’t See File Extensions on My Files?)
By default, Windows shows file extensions. For a while—in Windows 7, 8, and even 10—this was not true, but fortunately, they changed the default settings. We say fortunately because we feel showing file extensions is not only more helpful, but more secure. Without file extensions showing, it can be hard to tell whether that PDF file you’re looking at (for example) is really a PDF file and not some malicious executable file.
默认情况下,Windows显示文件扩展名。 有一段时间(在Windows 7、8甚至10)中,这不是真的,但是幸运的是,他们更改了默认设置。 我们之所以说幸运,是因为我们觉得显示文件扩展名不仅更有用,而且更安全。 如果没有显示文件扩展名,则很难分辨您正在查看的PDF文件(例如)是否真的是PDF文件,而不是某些恶意的可执行文件。
If file extensions are not showing for you in Windows, they’re easy enough to turn back on. In any File Explorer window, just head to View > Options > Change folder and search options. In the Folder Options window, on the View tab, disable the “Hide extensions for known file types” check box.
如果Windows中没有显示文件扩展名,则很容易重新打开。 在任何“文件资源管理器”窗口中,只需转到视图>选项>更改文件夹和搜索选项。 在“文件夹选项”窗口的“视图”选项卡上,禁用“隐藏已知文件类型的扩展名”复选框。
![](https://i-blog.csdnimg.cn/blog_migrate/9bba244ba631aeb37f6441411047315b.png)
File extensions do not show up in macOS by default. The reason for this is that macOS doesn’t really use extensions the same way that Windows does (and we’ll talk about that more in the next section).
默认情况下,文件扩展名不显示在macOS中。 原因是macOS并没有像Windows那样真正使用扩展(我们将在下一节中讨论更多内容)。
You can make macOS show file extensions, though, and it’s probably not a bad idea to do so. With Finder open, just head to Finder > Preferences > Advanced, and then enable the “Show all filename extensions” check box.
但是,您可以使macOS显示文件扩展名,这样做可能不是一个坏主意。 在Finder打开的情况下,只需转到Finder>首选项>高级,然后启用“显示所有文件扩展名”复选框。
![](https://i-blog.csdnimg.cn/blog_migrate/6871768abcc57246d27acd6c3fe65fa8.png)
macOS和Linux如何使用文件扩展名? (How Do macOS And Linux Use File Extensions?)
So, we talked about how Windows uses file extensions to know what type of file it’s dealing with, and what app to use when you open the file. Windows knows that a file named readme.txt is a text file because of that TXT file extension, and it knows to open it with your default text editor. Delete that extension, and Windows won’t know what to do with the file anymore.
因此,我们讨论了Windows如何使用文件扩展名来了解它正在处理的文件类型以及打开文件时使用的应用程序。 由于该TXT文件扩展名,Windows知道名为readme.txt的文件是文本文件,并且它知道使用默认的文本编辑器将其打开。 删除该扩展名,Windows将不再知道如何处理该文件。
While macOS and Linux still use file extensions, they don’t rely on them like Windows does. Instead, they use something called MIME types and creator codes to determine what a file is. This information is stored within the header of the file, and both macOS and Linux use that information to determine what type of file they’re dealing with.
尽管macOS和Linux仍使用文件扩展名,但它们不像Windows那样依赖它们。 相反,他们使用称为MIME类型和创建者代码的名称来确定文件是什么。 此信息存储在文件的标头中,macOS和Linux都使用该信息来确定他们正在处理的文件类型。
Since file extensions aren’t really required on macOS or Linux, you could very well have a valid file with no extension, but the OS could still open the file with the right program because of the file information contained in the file header.
由于macOS或Linux上实际上并不需要文件扩展名,因此您很可能拥有一个没有扩展名的有效文件,但是由于文件头中包含文件信息,因此OS仍可以使用正确的程序打开文件。
We won’t dive too much more into this here, but if you’re interested in learning more, check out our guide to why Linux and macOS don’t need file extensions.
我们在这里不会对此进行过多介绍,但是如果您有兴趣了解更多信息,请查看我们的指南,了解为什么Linux和macOS不需要文件扩展名。
如果更改文件扩展名会怎样? (What Happens If I Change A File’s Extension?)
Based on what we just talked about in the previous section, what happens when you change a file’s extension kind of depends on what operating system you’re using.
根据上一节中刚刚讨论的内容,更改文件扩展名类型时会发生什么情况取决于所使用的操作系统。
In Windows, if you delete a file extension, Windows no longer knows what to do with that file. When you try to open the file, Windows will ask you what app you want to use. If you change an extension—say you rename a file from “coolpic.jpg” to “coolpic.txt”—Windows will try to open the file in the app associated with the new extension, and you’ll either get an error message or an opened, but useless, file. In this example, Notepad (or whatever your default text editor is) did open our “coolpic.txt” file, but it’s just a garbled mess of text.
在Windows中,如果删除文件扩展名,Windows将不再知道如何处理该文件。 当您尝试打开文件时,Windows会询问您要使用的应用程序。 如果您更改扩展名(例如,将文件从“ coolpic.jpg”重命名为“ coolpic.txt”),则Windows将尝试在与新扩展名关联的应用程序中打开该文件,您将收到错误消息或已打开但无用的文件。 在此示例中,记事本(或任何默认的文本编辑器)确实打开了我们的“ coolpic.txt”文件,但这只是乱七八糟的文本。
![](https://i-blog.csdnimg.cn/blog_migrate/427ea5d79b7a8a4b9777bcc854cc5a74.png)
For that reason, Windows warns you whenever you try to change a file’s extension, and you have to confirm the action.
因此,当您尝试更改文件扩展名时,Windows会警告您,并且您必须确认操作。
![](https://i-blog.csdnimg.cn/blog_migrate/e35a6f88d8e9df5edb3fa2e0c0571f79.png)
If you’re using macOS, something similar happens. You still get a warning message if you try to change a file’s extension.
如果您使用的是macOS,则会发生类似的情况。 如果尝试更改文件的扩展名,仍然会收到警告消息。
![](https://i-blog.csdnimg.cn/blog_migrate/cf219b07f3b4b1e1634484cd30d349eb.png)
If you change the extension to something else, macOS will try to open the file in the app associated with the new extension. And, you’ll either get an error message or a garbled file—just like in Windows.
如果将扩展名更改为其他名称,macOS将尝试在与新扩展名关联的应用程序中打开文件。 而且,您将收到错误消息或乱码文件,就像在Windows中一样。
What’s different from Windows is that if you try to delete a file’s extension in macOS (at least in the Finder), macOS just adds the same extension right back, using data from the file’s MIME type.
与Windows的不同之处在于,如果您尝试删除macOS中的文件扩展名(至少在Finder中),则macOS会使用文件的MIME类型中的数据立即添加相同的扩展名。
If you actually want to change a file’s type—say for example, you wanted to change an image from the JPG to PNG format—you’d need to use software that can actually convert the file.
如果您实际上要更改文件的类型(例如,要将图像从JPG更改为PNG格式),则需要使用可以实际转换文件的软件。
如何更改打开文件的程序 (How to Change the Program That Opens a File)
Whenever you install an app that can open a particular file type, that app and the file extension get registered with your operating system. It’s entirely possible to have multiple apps that can open the same type of file. You can fire up an app, and then load any supported file type into it. Or, you can right-click a file to open its context menu and choose an available app there.
每当您安装可打开特定文件类型的应用程序时,该应用程序和文件扩展名都会在您的操作系统中注册。 完全可能有多个可以打开相同类型文件的应用程序。 您可以启动一个应用程序,然后将任何受支持的文件类型加载到该应用程序中。 或者,您可以右键单击文件以打开其上下文菜单,然后在此处选择一个可用的应用程序。
For example, in the image below, you can see that we’ve got a number of image apps on our Windows system that can open the “coolpic.jpg” file we’ve right-clicked.
例如,在下面的图像中,您可以看到我们的Windows系统上有许多图像应用程序可以打开我们右键单击的“ coolpic.jpg”文件。
![](https://i-blog.csdnimg.cn/blog_migrate/d0f4b31b44ec56593c42b573df5d2c89.png)
However, there’s also a default app associated with each extension. It’s the app that opens when you double-click a file, and in Windows it’s also the app that appears at the top of the list you get when you right-click a file (IrfanView in the image above).
但是,每个扩展也有一个默认应用程序。 双击文件时将打开该应用程序,而在Windows中,右键单击文件时,该应用程序也会显示在列表顶部(上图中的IrfanView)。
And you can change that default app. Just head to Settings > Apps > Default Apps > Choose default apps by file type. Scroll through the (very long) list of file types to find the one you want, and then click the currently-associated app on the right to change it. Check out our full guide to setting your default apps in Windows for more information.
您可以更改该默认应用。 只需转到设置>应用>默认应用>按文件类型选择默认应用即可。 滚动浏览(很长)文件类型列表以找到所需的文件类型,然后单击右侧的当前关联的应用程序进行更改。 查看我们的完整指南,了解如何在Windows中设置默认应用程序,以获取更多信息。
![](https://i-blog.csdnimg.cn/blog_migrate/97d452fabb455a64dbd6bf7f57208c25.png)
And you can do the same thing in macOS. Just select a file of the type you want to change, and then select File > Get Info from the main menu. In the Info window that pops up, head down to the “Open With” section, and then use the dropdown menu to select a new app. Easy enough.
您可以在macOS中执行相同的操作。 只需选择要更改类型的文件,然后从主菜单中选择“文件”>“获取信息”。 在弹出的“信息”窗口中,向下转到“打开方式”部分,然后使用下拉菜单选择一个新应用。 很简单。
![](https://i-blog.csdnimg.cn/blog_migrate/34da4a04af982599963c2ce05c011484.png)
Image Credit: CC0 Creative Commons/Pixabay
图片来源: CC0创用CC / Pixabay
翻译自: https://www.howtogeek.com/356448/what-is-a-file-extension/