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 β€” make mimetype behave a little more file(1) compatible. this gets turned on automatically when you call mimetype by a link called file.
    • 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 original file command, just so you know πŸ™ˆ)
    • also the default becomes to print descriptions instead of mimetypes.
  • -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_HOME
  • XDG_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 use update-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 --describe switch.

πŸ’€ 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 (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