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 Copiar enlaceEnlace copiado en el portapapeles!
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
media-type/subtype-identifier
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 Copiar enlaceEnlace copiado en el portapapeles!
You can add a custom MIME type for all the users on the system and register a default application for that MIME type.
Procedure
Create the
/usr/share/mime/packages/application-x-newtype.xml
file with following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The sample
application-x-newtype.xml
file here defines a new MIME typeapplication/x-newtype
and assigns file names with the.xyz
extension to that MIME type.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
[Desktop Entry] Type=Application MimeType=application/x-newtype Name=My Application 1 Exec=myapplication1 field_code
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The sample
myapplication1.desktop
file here associates theapplication/x-newtype
MIME type with an application namedMy Application 1
. It is run by a commandmyapplication1
.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
Exec=myapplication1 %F
Copy to Clipboard Copied! Toggle word wrap Toggle overflow As a root user, update the MIME database for your changes to take effect.
update-mime-database /usr/share/mime
# update-mime-database /usr/share/mime
Copy to Clipboard Copied! Toggle word wrap Toggle overflow As a root user, update the application database.
update-desktop-database /usr/share/applications
# update-desktop-database /usr/share/applications
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
To verify that you have successfully associated
*.xyz
files with theapplication/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"
$ touch test.xyz $ gvfs-info test.xyz | grep "standard::content-type" standard::content-type: application/x-newtype
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To verify
myapplication1.desktop
is correctly set as the default registered application for theapplication/x-newtype
MIME type, execute following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
11.3. Adding a custom MIME type for individual users Copiar enlaceEnlace copiado en el portapapeles!
You can add a custom MIME type for individual user on the system and register a default application for that MIME type.
Procedure
Create the
~/.local/share/mime/packages/application-x-newtype.xml
file with following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The sample
application-x-newtype.xml
file here defines a new MIME typeapplication/x-newtype
and assigns file names with the.xyz
extension to that MIME type.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
[Desktop Entry] Type=Application MimeType=application/x-newtype Name=My Application 1 Exec=myapplication1 field_code
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The sample
myapplication1.desktop
file above associates theapplication/x-newtype
MIME type with an application named My Application 1. It is run by a commandmyapplication1
.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
Exec=myapplication1 %F
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Update the MIME database for your changes to take effect:
update-mime-database ~/.local/share/mime
$ update-mime-database ~/.local/share/mime
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Update the application database:
update-desktop-database ~/.local/share/applications
$ update-desktop-database ~/.local/share/applications
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
To verify that you have successfully associated
*.xyz
files with theapplication/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"
$ touch test.xyz $ gvfs-info test.xyz | grep "standard::content-type" standard::content-type: application/x-newtype
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To verify that
myapplication1.desktop
is correctly set as the default registered application for theapplication/x-newtype
MIME type, execute following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
11.4. Options to override default MIME types Copiar enlaceEnlace copiado en el portapapeles!
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:
-
/usr/share/applications/
-
/etc/xdg/
-
~/.local/share/application/
Within a particular location, the configurations are applied in the following order:
- mimeapps.list
- gnome-mimeapps.list
11.5. Overriding default registered application for all the users Copiar enlaceEnlace copiado en el portapapeles!
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
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 themimeapps.list
file specifies the default registered application for thetext/html
andapplication/xhtml+xml
MIME types:[Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktop
[Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktop
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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.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
[Default Applications] text/html=myapplication1.desktop application/xhtml+xml=myapplication2.desktop
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This example above sets the default registered application for the
text/html
MIME type tomyapplication1.desktop
andapplication/xhtml+xml
MIME type tomyapplication2.desktop
.
Verification
-
For these settings to function correctly, ensure that both the
myapplication1.desktop
andmyapplication2.desktop
files are placed in the/usr/share/applications/
directory. Verify that the default registered application is set correctly:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
11.6. Overriding default registered application for individual users Copiar enlaceEnlace copiado en el portapapeles!
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
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 themimeapps.list
file specifies the default registered application for thetext/html
andapplication/xhtml+xml
MIME types:[Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktop
[Default Applications] text/html=firefox.desktop application/xhtml+xml=firefox.desktop
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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.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
[Default Applications] text/html=myapplication1.desktop application/xhtml+xml=myapplication2.desktop
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This example above sets the default registered application for the
text/html
MIME type tomyapplication1.desktop
andapplication/xhtml+xml
MIME type tomyapplication2.desktop
.
Verification
-
For these settings to function correctly, ensure that both the
myapplication1.desktop
andmyapplication2.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.Copy to Clipboard Copied! Toggle word wrap Toggle overflow