12.3. Configuring File Associations
12.3.1. What Are MIME Types?
- Determine which application should open a specific file format by default.
- Register other applications that can also open a specific file format.
- Provide a string describing the type of a file, for example, in a file properties dialog of the Files application.
- Provide an icon representing a specific file format, for example, in a file properties dialog of the Files application.
media-type/subtype-identifier
Example 12.7. MIME Types Format
image/jpeg is an example of a MIME type where image is the media type, and jpeg is the subtype identifier.
- The machine-wide and user-specific location to store all MIME type specification files.
- How to register a MIME type so that the desktop environment knows which applications can be used to open a specific file format.
- How the user can change which applications should open what file formats.
12.3.1.1. What Is the MIME Database?
/usr/share/mime/packages/ directory where the MIME type related files specifying information on known MIME types are stored. One example of such a file is /usr/share/mime/packages/freedesktop.org.xml, specifying information about the standard MIME types available on the system by default. That file is provided by the shared-mime-info package.
Getting More Information
12.3.2. Adding a Custom MIME Type for All Users
/usr/share/mime/packages/ directory and a .desktop file in the /usr/share/applications/ directory.
Procedure 12.3. Adding a Custom application/x-newtype MIME Type for All Users
- Create the
/usr/share/mime/packages/application-x-newtype.xmlfile:<?xml version="1.0" encoding="UTF-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-type type="application/x-newtype"> <comment>new mime type</comment> <glob pattern="*.xyz"/> </mime-type> </mime-info>The sampleapplication-x-newtype.xmlfile above defines a new MIME typeapplication/x-newtypeand assigns file names with the.xyzextension to that MIME type. - Create a new
.desktopfile named, for example,myapplication1.desktop, and place it in the/usr/share/applications/directory:[Desktop Entry] Type=Application MimeType=application/x-newtype Name=My Application 1 Exec=myapplication1
The samplemyapplication1.desktopfile above associates theapplication/x-newtypeMIME type with an application named My Application 1, which is run by a commandmyapplication1. - As root, update the MIME database for your changes to take effect:
#update-mime-database /usr/share/mime - As root, update the application database:
#update-desktop-database /usr/share/applications - To verify that you have successfully associated
*.xyzfiles with theapplication/x-newtypeMIME type, first create an empty file, for exampletest.xyz:$touch test.xyzThen run thegvfs-infocommand:$gvfs-info test.xyz | grep "standard::content-type"standard::content-type: application/x-newtype - To verify that
myapplication1.desktophas been correctly set as the default registered application for theapplication/x-newtypeMIME type, run thegvfs-mime --querycommand:$gvfs-mime --query application/x-newtypeDefault application for 'application/x-newtype': myapplication1.desktop Registered applications: myapplication1.desktop Recommended applications: myapplication1.desktop
12.3.3. Adding a Custom MIME Type for Individual Users
~/.local/share/mime/packages/ directory and a .desktop file in the ~/.local/share/applications/ directory.
Procedure 12.4. Adding a Custom application/x-newtype MIME Type for Individual Users
- Create the
~/.local/share/mime/packages/application-x-newtype.xmlfile:<?xml version="1.0" encoding="UTF-8"?> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"> <mime-type type="application/x-newtype"> <comment>new mime type</comment> <glob pattern="*.xyz"/> </mime-type> </mime-info>The sampleapplication-x-newtype.xmlfile above defines a new MIME typeapplication/x-newtypeand assigns file names with the.xyzextension to that MIME type. - Create a new
.desktopfile named, for example,myapplication1.desktop, and place it in the~/.local/share/applications/directory:[Desktop Entry] Type=Application MimeType=application/x-newtype Name=My Application 1 Exec=myapplication1
The samplemyapplication1.desktopfile above associates theapplication/x-newtypeMIME type with an application named My Application 1, which is run by a commandmyapplication1. - Update the MIME database for your changes to take effect:
$update-mime-database ~/.local/share/mime - Update the application database:
$update-desktop-database ~/.local/share/applications - To verify that you have successfully associated
*.xyzfiles with theapplication/x-newtypeMIME type, first create an empty file, for exampletest.xyz:$touch test.xyzThen run thegvfs-infocommand:$gvfs-info test.xyz | grep "standard::content-type"standard::content-type: application/x-newtype - To verify that
myapplication1.desktophas been correctly set as the default registered application for theapplication/x-newtypeMIME type, run thegvfs-mime --querycommand:$gvfs-mime --query application/x-newtypeDefault application for 'application/x-newtype': myapplication1.desktop Registered applications: myapplication1.desktop Recommended applications: myapplication1.desktop
12.3.4. Overriding the Default Registered Application for All Users
/usr/share/applications/defaults.list file specifies which application is registered to open specific MIME types by default. To override the system defaults for all users on the system, you need to create a /usr/share/applications/mimeapps.list file with a list of MIME types for which you want to override the default registered application.
Procedure 12.5. Overriding the Default Registered Application for All Users
- Consult the
/usr/share/applications/defaults.listfile to determine the MIME types for which you want to change the default registered application. For example, the following sample of thedefaults.listfile specifies the default registered application for thetext/htmlandapplication/xhtml+xmlMIME types:[Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktop
The default application (Firefox) is defined by specifying its corresponding.desktopfile (firefox.desktop). The default location for other applications'.desktopfiles is/usr/share/applications/. - Create the
/usr/share/applications/mimeapps.listfile. In the file, specify the MIME types and their corresponding default registered applications:[Default Applications] text/html=myapplication1.desktop application/xhtml+xml=myapplication2.desktop [Added Associations] text/html=myapplication1.desktop; application/xhtml+xml=myapplication2.desktop;
This sets the default registered application for thetext/htmlMIME type tomyapplication1.desktop, and the default registered application for theapplication/xhtml+xmlMIME type tomyapplication2.desktop.For these settings to function properly, ensure that both themyapplication1.desktopandmyapplication2.desktopfiles are placed in the/usr/share/applications/directory. - You can use the
gvfs-mime --querycommand to verify that the default registered application has been set correctly:$gvfs-mime --query text/htmlDefault application for 'text/html': myapplication1.desktop Registered applications: myapplication1.desktop firefox.desktop Recommended applications: myapplication1.desktop firefox.desktop
12.3.5. Overriding the Default Registered Application for Individual Users
/usr/share/applications/defaults.list file specifies which application is registered to open specific MIME types by default. To override the system defaults for individual users, you need to create a ~/.local/share/applications/mimeapps.list file with a list of MIME types for which you want to override the default registered application.
Procedure 12.6. Overriding the Default Registered Application for Individual Users
- Consult the
/usr/share/applications/defaults.listfile to determine the MIME types for which you want to change the default registered application. For example, the following sample of thedefaults.listfile specifies the default registered application for thetext/htmlandapplication/xhtml+xmlMIME types:[Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktop
The default application (Firefox) is defined by specifying its corresponding.desktopfile (firefox.desktop). The system default location for other applications'.desktopfiles is/usr/share/applications/. Individual users'.desktopfiles can be stored in~/.local/share/applications/. - Create the
~/.local/share/applications/mimeapps.listfile. In the file, specify the MIME types and their corresponding default registered applications:[Default Applications] text/html=myapplication1.desktop application/xhtml+xml=myapplication2.desktop [Added Associations] text/html=myapplication1.desktop; application/xhtml+xml=myapplication2.desktop;
This sets the default registered application for thetext/htmlMIME type tomyapplication1.desktop, and the default registered application for theapplication/xhtml+xmlMIME type tomyapplication2.desktop.For these settings to function properly, ensure that both themyapplication1.desktopandmyapplication2.desktopfiles are placed in the/usr/share/applications/directory. - You can use the
gvfs-mime --querycommand to verify that the default registered application has been set correctly:$gvfs-mime --query text/htmlDefault application for 'text/html': myapplication1.desktop Registered applications: myapplication1.desktop firefox.desktop Recommended applications: myapplication1.desktop firefox.desktop

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.