MIMETYPE(1p)
β¨ MIMETYPE(1p) β¨
okay so bestie, welcome to mimetype β she's a little Perl script with BIG main character energy, and she's about to tell you what a file actually is. not what it's called, not what it's pretending to be. what it is. π
π NAME π
mimetype β determine file type. that's it, that's the gig. π
π¦ SYNOPSIS π¦
mimetype [options] [-] files
π DESCRIPTION π
okay so here's the tea, this script tries to figure out the mime type of a file using the Shared MIME-info database. she's giving file(1) work-alike, but instead of handing you descriptions she hands you mimetypes. same energy, different outfit. β¨
if you symlink the file command to mimetype, she'll behave a little more compatible β go look at --file-compat for the deets. and ngl, the commandline options for specifying alternative magic files are not implemented the same way, because the data formats are out here beefing with each other. also the wording of the descriptions will differ, so don't come for her. π
for naming switches she followed the manpage of file(1) version 4.02 whenever possible. and the way those switches seem to differ completely from the spec in the 'utilities' chapter of IEEE Std 1003.1-2001 (POSIX)? iconic of them honestly. π
πΈ OPTIONS πΈ
-a,--allβ show output of all rules that match the file.
TODO: this method now just returns one match for each method (globs, magic, etc.). so like, she's trying bestie.
-b,--briefβ do not prepend filenames to output lines (brief mode). minimalism era. π--database=mimedir:mimedir:...β force the program to look in these directories for the shared mime-info database. The directories specified by the basedir specification are ignored. (yes, ignored, she said what she said.)-d,--describeβ print file descriptions instead of mime types, this is the default when using--file-compat.-D,--debugβ print debug information about how the mimetype was determined. detective mode π-f namefile,--namefile=namefileβ read the names of the files to be examined from the file 'namefile' (one per line) before the argument list.--file-compatβ makemimetypebehave a little more file(1) compatible. this is turned on automatically when you callmimetypeby a link called 'file'.
A single - won't be considered a separator between options and filenames anymore, but becomes identical to --stdin. ( You can still use -- as separator, but that is not backward compatible with the original file command. ) Also the default becomes to print descriptions instead of mimetypes.
-F string,--separator=stringβ use string as custom separator between the file name and its mimetype or description, defaults to:.-h,--help-u,--usage
print a help message and exits. π«Ά
-i,--mimetypeβ use mime types, opposite to--describe, this is the default when _not_ using--file-compat.-L,--dereferenceβ follow symbolic links. she's not afraid of commitment. π₯-l code,--language=codeβ the language attribute specifies a two letter language code, this makes descriptions being outputted in the specified language. multilingual queen π-M,--magic-onlyβ do not check for extensions, globs or inode type, only look at the content of the file. this is particularly useful if for some reason you don't trust the name or the extension a file has. (and honestly? valid. π©)-N,--noalignβ do not align output fields.--output-formatβ if you want an alternative output format, you can specify a format string containing the following escapes:
%f for the filename
%d description
%m mime type
Alignment is not available when using this, you need to post-process the output to do that. π
--stdinβ determine type of content from STDIN, less powerful then normal file checking because it only uses magic typing. this will happen also if the STDIN filehandle is a pipe.
To use this option IO::Scalar needs to be installed. no module, no vibe check. π
-v,--versionβ print the version of the program and exit.
π ENVIRONMENT π
XDG_DATA_HOMEXDG_DATA_DIRS
these variables can list base directories to search for data files. the shared mime-info will be expected in the "mime" sub directory of one of these directories. if these are not set, there will be searched for the following directories:
$HOME/.local/share/mime
/usr/local/share/mime
/usr/share/mime
see also the "XDG Base Directory Specification" <http://freedesktop.org/Standards/basedir-spec> β go read it, she's an icon too. π
π§ FILES π§
the base dir for all data files is determined by two environment variables, see "ENVIRONMENT".
BASE/mime/packages/SOURCE.xmlβ all other files are compiled from these source files. to re-compile them use update-mime-database(1).BASE/mime/globsβ compiled information about globs.BASE/mime/magicβ compiled information about magic numbers. β¨BASE/mime/MEDIA/SUBTYPE.xmlβ descriptions of a mimetype in multiple languages, used for the--describeswitch.
π©Ί DIAGNOSTICS π©Ί
if a file has an empty mimetype or an empty description, most probably the file doesn't exist and the given name doesn't match any globs. an empty description can also mean that there is no description available in the language you specified. (so like, don't panic, but alsoβ¦ maybe panic a little? no bestie, don't. π)
the program exits with a non-zero exit value if either the commandline arguments failed, a module it depends on wasn't found or the shared mime-info database wasn't accessible. see File::MimeInfo for more details.
β TODO β
the --all switch doesn't really show all matches, but only one per mime-typing method. this needs to be implemented in the modules first. she's aware. she's working on it. periodt. π
π BUGS π
if you find bugs, please file them in our Github issue tracker at <https://codeberg.org/michielb/File-MimeInfo/issues>. (yes bestie we know, the URL says Github and the link says codeberg. she contains multitudes. π«Ά)
mimetype doesn't provide a switch for looking inside compressed files because it seems to me that this can only be done by un-compressing the file, something that defeats the purpose. on the other hand the option should exist for strict compatibility with file(1). possibly a subclass should be made for this one day. π
π AUTHOR π
Jaap Karssenberg <pardus@cpan.org> β maintained by Michiel Beijen <mb@x14.nl>. the parents of this whole operation. π«‘
π COPYRIGHT π
Copyright (c) 2003, 2012 Jaap G Karssenberg. All rights reserved.
Copyright (c) 2013-2026 Michiel W. Beijen. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. read that again, bestie. no promises. π¨
π SEE ALSO π
file(1), update-mime-database(1), File::MimeInfo(3), <http://freedesktop.org/Software/shared-mime-info>
okay that's the whole page, you're officially caught up. π this edition was served fresh by perl v5.40.1 on 2026-05-20 β that's the MIMETYPE(1p) footer, babes, and she ate. πΈπ β¨
π¦ where this page comes from
- ubuntu stonking: libfile-mimeinfo-perl 0.37-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms