Este contenido no está disponible en el idioma seleccionado.

Chapter 11. Configuring file associations


You can configure RHEL to open or access files with different formats.

In GNOME, MIME (Multipurpose Internet Mail Extension) types help to identify the format of a file and applications to use to open these files.

11.1. Multipurpose Internet Mail Extension types

The GNOME desktop uses MIME types to:

  • Determine which application should open a specific file format by default
  • Register other applications that can open files of a specific format
  • Set a string describing the type of a file, for example, in a file properties dialog of the files application
  • Set an icon representing a specific file format, for example, in a file properties dialog of the files application

MIME type names follow a given format:

media-type/subtype-identifier
Copy to Clipboard Toggle word wrap
Note

In the image/jpeg MIME type name, image is a media type and jpeg is the subtype identifier.

GNOME follows Multipurpose Internet Mail Extension (MIME) info specification from the Freedesktop.org project to determine the following information:

  • The machine-wide and user-specific location to store all the MIME type specification files
  • How to register a MIME type so that the desktop environment knows which application you can use to open a specific file format
  • How users can change which applications should open with what file formats

MIME database

The MIME database is a collection of all the MIME type specification files that GNOME uses to store information about known MIME types.

The most important part of the MIME database from the system administrator’s point of view is the /usr/share/mime/packages/ directory, where the MIME type-related files specifying information about 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. The shared-mime-info package provides this file.

11.2. Adding a custom MIME type for all users

You can add a custom MIME type for all the users on the system and register a default application for that MIME type.

Procedure

  1. Create the /usr/share/mime/packages/application-x-newtype.xml file with following content:

    <?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>
    Copy to Clipboard Toggle word wrap

    The sample application-x-newtype.xml file here defines a new MIME type application/x-newtype and assigns file names with the .xyz extension to that MIME type.

  2. Create a new .desktop file named, for example, myapplication1.desktop in the /usr/share/applications/ with following content:

    [Desktop Entry]
    Type=Application
    MimeType=application/x-newtype
    Name=My Application 1
    Exec=myapplication1 field_code
    Copy to Clipboard Toggle word wrap

    The sample myapplication1.desktop file here associates the application/x-newtype MIME type with an application named My Application 1. It is run by a command myapplication1.

    Based on how myapplication1 gets started, select one relevant field code from Desktop Entry Specification. For example, for an application capable of opening multiple files, use:

    Exec=myapplication1 %F
    Copy to Clipboard Toggle word wrap
  3. As a root user, update the MIME database for your changes to take effect.

    # update-mime-database /usr/share/mime
    Copy to Clipboard Toggle word wrap
  4. As a root user, update the application database.

    # update-desktop-database /usr/share/applications
    Copy to Clipboard Toggle word wrap

Verification

  1. To verify that you have successfully associated *.xyz files with the application/x-newtype MIME type, first create an empty file, for example test.xyz and execute the following commands:

    $ touch test.xyz
    
    $ gvfs-info test.xyz | grep "standard::content-type"
      standard::content-type: application/x-newtype
    Copy to Clipboard Toggle word wrap
  2. To verify myapplication1.desktop is correctly set as the default registered application for the application/x-newtype MIME type, execute following command:

    $ gio mime --query application/x-newtype
    Default application for 'application/x-newtype': myapplication1.desktop
    Registered applications:
    	myapplication1.desktop
    Recommended applications:
    	myapplication1.desktop
    Copy to Clipboard Toggle word wrap

11.3. Adding a custom MIME type for individual users

You can add a custom MIME type for individual user on the system and register a default application for that MIME type.

Procedure

  1. Create the ~/.local/share/mime/packages/application-x-newtype.xml file with following content:

    <?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>
    Copy to Clipboard Toggle word wrap

    The sample application-x-newtype.xml file here defines a new MIME type application/x-newtype and assigns file names with the .xyz extension to that MIME type.

  2. Create a new .desktop file named, for example, myapplication1.desktop, and place it in the ~/.local/share/applications/ directory with following content:

    [Desktop Entry]
    Type=Application
    MimeType=application/x-newtype
    Name=My Application 1
    Exec=myapplication1 field_code
    Copy to Clipboard Toggle word wrap

    The sample myapplication1.desktop file above associates the application/x-newtype MIME type with an application named My Application 1. It is run by a command myapplication1.

    Based on how myapplication1 gets started, choose one respective field code from Desktop Entry Specification. For example, for an application capable of opening multiple files, use:

    Exec=myapplication1 %F
    Copy to Clipboard Toggle word wrap
  3. Update the MIME database for your changes to take effect:

    $ update-mime-database ~/.local/share/mime
    Copy to Clipboard Toggle word wrap
  4. Update the application database:

    $ update-desktop-database ~/.local/share/applications
    Copy to Clipboard Toggle word wrap

Verification

  1. To verify that you have successfully associated *.xyz files with the application/x-newtype MIME type, first create an empty file, for example, test.xyz and execute the following commands:

    $ touch test.xyz
    
    $ gvfs-info test.xyz | grep "standard::content-type"
      standard::content-type: application/x-newtype
    Copy to Clipboard Toggle word wrap
  2. To verify that myapplication1.desktop is correctly set as the default registered application for the application/x-newtype MIME type, execute following command:

    $ gio mime --query application/x-newtype
    Default application for 'application/x-newtype': myapplication1.desktop
    Registered applications:
    	myapplication1.desktop
    Recommended applications:
    	myapplication1.desktop
    Copy to Clipboard Toggle word wrap

11.4. Options to override default MIME types

By default, the package-installed /usr/share/applications/mimeapps.list and /usr/share/applications/gnome-mimeapps.list files specify the application registered to open specific MIME types.

System administrators can create the /etc/xdg/mimeapps.list or /etc/xdg/gnome-mimeapps.list file with a list of MIME types they want to override with the default registered application.

Local users can create the ~/.local/share/applications/mimeapps.list or ~/.local/share/applications/gnome-mimeapps.list file with a list of MIME types for which they want to override the default registered application.

Configurations are applied in the following order:

  1. /usr/share/applications/
  2. /etc/xdg/
  3. ~/.local/share/application/

Within a particular location, the configurations are applied in the following order:

  1. mimeapps.list
  2. gnome-mimeapps.list

11.5. Overriding default registered application for all the users

As a system administer, you can update the configuration based on the requirements. System administrator’s configuration takes precedence over default package configuration. Within each, the desktop-specific configuration takes precedence over the configuration that does not specify the desktop environment.

Procedure

  1. Consult the /usr/share/applications/mimeapps.list file to determine the MIME types for which you want to change the default registered application. For example, the following sample of the mimeapps.list file specifies the default registered application for the text/html and application/xhtml+xml MIME types:

    [Default Applications]
    text/html=firefox.desktop
    application/xhtml+xml=firefox.desktop
    Copy to Clipboard Toggle word wrap

    This example above specifies default application (Mozilla Firefox) by specifying its corresponding .desktop file (firefox.desktop). You can find .desktop files for other applications in the /usr/share/applications/ directory.

  2. Create the /etc/xdg/mimeapps.list file and specify the MIME types and their corresponding default registered applications in this file.

    [Default Applications]
    text/html=myapplication1.desktop
    application/xhtml+xml=myapplication2.desktop
    Copy to Clipboard Toggle word wrap

    This example above sets the default registered application for the text/html MIME type to myapplication1.desktop and application/xhtml+xml MIME type to myapplication2.desktop.

Verification

  • For these settings to function correctly, ensure that both the myapplication1.desktop and myapplication2.desktop files are placed in the /usr/share/applications/ directory.
  • Verify that the default registered application is set correctly:

    $ gio mime text/html
    Default application for 'text/html': myapplication1.desktop
    Registered applications:
    	myapplication1.desktop
    	firefox.desktop
    Recommended applications:
    	myapplication1.desktop
    	firefox.desktop
    Copy to Clipboard Toggle word wrap

11.6. Overriding default registered application for individual users

Individual users can also update the configuration based on the requirements. This configuration takes precedence over the system administrator’s configuration and the system administrator’s configuration takes precedence over the package configuration. Within each, the desktop-specific configuration takes precedence over the configuration that does not specify the desktop environment.

Procedure

  1. Consult the /usr/share/applications/mimeapps.list file to determine the MIME types for which you want to change the default registered application. For example, the following sample of the mimeapps.list file specifies the default registered application for the text/html and application/xhtml+xml MIME types:

    [Default Applications]
    text/html=firefox.desktop
    application/xhtml+xml=firefox.desktop
    Copy to Clipboard Toggle word wrap

    This example above specifies default application (Mozilla Firefox) by specifying its corresponding .desktop file (firefox.desktop). You can find .desktop files for other applications in the /usr/share/applications/ directory.

  2. Create the ~/.local/share/applications/mimeapps.list file and specify the MIME types and their corresponding default registered applications in this file.

    [Default Applications]
    text/html=myapplication1.desktop
    application/xhtml+xml=myapplication2.desktop
    Copy to Clipboard Toggle word wrap

    This example above sets the default registered application for the text/html MIME type to myapplication1.desktop and application/xhtml+xml MIME type to myapplication2.desktop.

Verification

  • For these settings to function correctly, ensure that both the myapplication1.desktop and myapplication2.desktop files are placed in the /usr/share/applications/ directory.
  • Execute the gio mime query command to verify that the default registered application is set correctly.

    $ gio mime text/html
    Default application for 'text/html': myapplication1.desktop
    Registered applications:
    	myapplication1.desktop
    	firefox.desktop
    Recommended applications:
    	myapplication1.desktop
    	firefox.desktop
    Copy to Clipboard Toggle word wrap
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat