LinuxCommandLibrary

update-mime-database

Update MIME type database

SYNOPSIS

update-mime-database [OPTION...] DIRECTORY
Example: sudo update-mime-database /usr/share/mime

PARAMETERS

--help, -h
    Display a help message and exit.

--version, -V
    Display version information and exit.

--verbose, -v
    Print detailed information about the actions being performed during the update process.

--no-fork, -n
    This option is deprecated and ignored in modern versions of shared-mime-info. Previously, it prevented the process from forking into the background.

--dry-run, -d
    Simulate the update process without actually making any changes to the database files. Useful for testing.

--debug
    Print extensive debugging information, primarily for developers.

DIRECTORY
    The path to the root directory containing the MIME type definitions (e.g., /usr/share/mime or ~/.local/share/mime). This argument is mandatory.

DESCRIPTION

update-mime-database is a utility program essential for Linux desktop environments and applications. It is responsible for building and updating the cache files used by the shared-mime-info package. MIME (Multipurpose Internet Mail Extensions) types are a standard way to classify file formats, enabling the operating system and applications to correctly identify and handle various types of content, such as text/plain, image/jpeg, or application/pdf.

The command scans a specified directory (typically /usr/share/mime for system-wide definitions or ~/.local/share/mime for user-specific ones) for XML files that define MIME types and their associated patterns. It then compiles this information into a compact, optimized binary cache file (mime.cache) that can be quickly read by applications. This caching process significantly speeds up file type detection, which is crucial for tasks like displaying correct icons in file managers, opening files with the appropriate application, or processing downloaded content.

Regular updates to this database ensure that new or modified file types are correctly recognized across the system. It is often run automatically during package installations that provide new MIME type definitions.

CAVEATS

To update the system-wide MIME database (e.g., in /usr/share/mime), the command must typically be run with superuser privileges (e.g., using sudo). Updates to user-specific databases (e.g., in ~/.local/share/mime) do not require special permissions.

While update-mime-database is robust, incorrect or malformed XML MIME definition files in the specified directory could lead to errors during the update process.

DATABASE LOCATION

The primary system-wide MIME database is typically located at /usr/share/mime. User-specific MIME type definitions can be placed in ~/.local/share/mime. When updating, update-mime-database should be pointed to one of these base directories.

AUTOMATIC UPDATES

Many Linux distributions automatically run update-mime-database as part of post-installation scripts for packages that provide new MIME type definitions (e.g., when installing new applications or icon themes), ensuring the system's file type recognition capabilities are always up-to-date.

HISTORY

The update-mime-database command is part of the shared-mime-info project, which was established to provide a common, standardized, and extensible MIME type database for freedesktop.org compliant desktop environments, such as GNOME and KDE. Before this, different desktop environments often had their own, incompatible ways of managing MIME types. The project aimed to centralize this, making it easier for applications to correctly identify file types across various desktop environments. Its development has been driven by the need for consistent and efficient file type detection in modern Linux systems, becoming a fundamental component of desktop environments since the early 2000s.

SEE ALSO

xdg-open(1), file(1), shared-mime-info(7), update-desktop-database(1)

Copied to clipboard