
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中沒有顯示文件擴展名,則很容易重新打開。 在任何“文件資源管理器”窗口中,只需轉到視圖>選項>更改文件夾和搜索選項。 在“文件夾選項”窗口的“視圖”選項卡上,禁用“隱藏已知文件類型的擴展名”復選框。

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>首選項>高級,然后啟用“顯示所有文件擴展名”復選框。

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”文件,但這只是亂七八糟的文本。

For that reason, Windows warns you whenever you try to change a file’s extension, and you have to confirm the action.
因此,當您嘗試更改文件擴展名時,Windows會警告您,并且您必須確認操作。

If you’re using macOS, something similar happens. You still get a warning message if you try to change a file’s extension.
如果您使用的是macOS,則會發生類似的情況。 如果嘗試更改文件的擴展名,仍然會收到警告消息。

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”文件。

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中設置默認應用程序,以獲取更多信息。

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中執行相同的操作。 只需選擇要更改類型的文件,然后從主菜單中選擇“文件”>“獲取信息”。 在彈出的“信息”窗口中,向下轉到“打開方式”部分,然后使用下拉菜單選擇一個新應用。 很簡單。

Image Credit: CC0 Creative Commons/Pixabay
圖片來源: CC0創用CC / Pixabay
翻譯自: https://www.howtogeek.com/356448/what-is-a-file-extension/