mimetype
Determine file's MIME type
TLDR
Print the MIME type of a given file
Display only the MIME type, and not the filename
Display a description of the MIME type
Determine the MIME type of stdin (does not check a filename)
Display debug information about how the MIME type was determined
Display all the possible MIME types of a given file in confidence order
Explicitly specify the 2-letter language code of the output
SYNOPSIS
mimetype [OPTION...] [FILE...]
PARAMETERS
-b, --brief
Print only MIME type, omit filename
-d, --debug
Show detailed detection process
-D, --dump
Dump XML mime.cache to stdout
-e, --extension
Print file extension for MIME type (implies -b)
-i, --stdin
Read single file from stdin
-I, --magic-file FILE
Use custom magic file
-l, --local
Use only local (~/.local/share/mime) database
-o, --output-format=FORMAT
Output in Nfo or XML format
--database=LOCATION
Specify custom MIME database path
-h, --help
Display help
-V, --version
Show version info
DESCRIPTION
The mimetype command identifies the MIME type of files or input data using the shared MIME-info database from the FreeDesktop.org project.
It analyzes file extensions, contents via magic patterns, and XML rules from the database (/usr/share/mime/packages/ and user-local overrides).
By default, it outputs filename: type/subtype. Useful for scripts, desktop environments (GNOME, KDE), and applications needing file type detection without parsing extensions alone.
Handles multiple files, stdin input, and supports custom databases or formats like XML/Nfo. Detection prioritizes content over extension for accuracy.
Ensures cross-desktop consistency; requires shared-mime-info package. Not infallible—relies on maintained magic rules—but highly reliable for common formats like images, documents, archives.
CAVEATS
Detection accuracy depends on updated MIME database; may misidentify ambiguous files. No network access for remote files.
EXAMPLES
mimetype document.pdf → document.pdf: application/pdf
mimetype -b image.png → image/png
mimetype -e application/pdf → .pdf
DATABASE LOCATION
System: /usr/share/mime
User: ~/.local/share/mime
Update with update-mime-database
HISTORY
Part of shared-mime-info project (2003+), created by Havoc Pennington for FreeDesktop.org to standardize MIME handling in Linux desktops like GNOME/KDE.
SEE ALSO
file(1), xdg-mime(1), update-mime-database(1)


