MIMETYPE(1)
π
MIMETYPE(1) β the mimetype page, but make it make sense π
okay so bestie, you're looking at mimetype β a little script from the User Contributed Perl Documentation corner of the universe, and honestly? she's iconic. let's get into it β¨
πΈ NAME πΈ
mimetype β determine file type. that's it. that's the whole job. she sniffs it out π΅οΈββοΈ
β SYNOPSIS β
mimetype [options] [-] files
literally just hand her some files and she'll tell you what they are π
π¦ DESCRIPTION π¦
so this script tries to determine the mime type of a file using the Shared MIME-info database. it's basically a file(1) work-alike, like a cousin who's similar but cooler β except she uses mimetypes instead of descriptions.
if you symlink the file command to mimetype, she'll behave a little more compatibly β peep --file-compat down below π. the commandline options for specifying alternative magic files are not implemented the same way, because the data formats conflict, okay? not her fault. also the wording of the descriptions will differ. accept it π
for naming switches she followed the manpage of file(1) version 4.02 when possible. those seem to differ completely from the spec in the 'utilities' chapter of IEEE Std 1003.1-2001 (POSIX). soβ¦ yeah. that's a whole thing π«
β¨ 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 her best π-b,--briefβ do not prepend filenames to output lines (brief mode). minimal. clean. main character energy π--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. you're the boss π«Ά-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, activated π-f namefile,--namefile=namefileβ read the names of the files to be examined from the file namefile (one per line) before the argument list. a whole guest list, love that for her π--file-compatβ makemimetypebehave a little morefile(1)compatible. this gets turned on automatically when you callmimetypeby a link calledfile.- a single
-won't be considered a separator between options and filenames anymore β it becomes identical to--stdin. (you can still use--as a separator, but that's not backward compatible with the originalfilecommand, just so you know π) - also the default becomes to print descriptions instead of mimetypes.
- a single
-F string,--separator=stringβ use string as a custom separator between the file name and its mimetype or description. defaults to':'. cute little colon moment π-h,--helpβ print a help message and exits.-u,--usageβ same vibe as-h: print a help message and exits.-i,--mimetypeβ use mime types, the opposite of--describe. this is the default when not using--file-compat.-L,--dereferenceβ follow symbolic links. no more hiding behind the link, bestie π-l code,--language=codeβ the language attribute specifies a two letter language code. this makes descriptions get outputted in the specified language π-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. honestly valid, be suspicious π₯-N,--noalignβ do not align output fields. chaos. love it.--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. DIY era π
--stdinβ determine type of content from STDIN. less powerful than 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 party π₯²
-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, iykyk π
π 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 useupdate-mime-database(1).BASE/mime/globsβ compiled information about globs.BASE/mime/magicβ compiled information about magic numbers. β¨magicβ¨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, it's not always a crash, sometimes it's just vibes π«
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 β only one per mime-typing method. this needs to be implemented in the modules first. so yeah, it's on the list, bestie βοΈ
π BUGS π
if you find bugs, please file them in our Github issue tracker at <https://github.com/mbeijen/File-MimeInfo/issues>. we will see them π
mimetype doesn't provide a switch for looking inside compressed files, because it seems to the author that this can only be done by un-compressing the file β something that defeats the purpose, honestly. on the other hand, the option should exist for strict compatibility with file(1). possibly a subclass should be made for this one day. someday. maybe. π
π AUTHOR π
Jaap Karssenberg <pardus@cpan.org> Maintained by Michiel Beijen <mb@x14.nl>
two icons, one page π«Ά
πΈ COPYRIGHT πΈ
Copyright (c) 2003, 2012 Jaap G Karssenberg. 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. fr fr, no promises π
π SEE ALSO π
file(1), update-mime-database(1), File::MimeInfo(3), <http://freedesktop.org/Software/shared-mime-info>
and that's the whole page, bestie π this one's perl v5.42.0, dated 2024-04-26, straight out of the MIMETYPE(1) manual β go forth and identify some files, slay β¨ππ¦
π¦ where this page comes from
- opensuse-leap 16.0: perl-File-MimeInfo 0.350.0-bp160.1.11 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms