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 β€” make mimetype behave a little more file(1) compatible. this is 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, 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_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, 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 --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, 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 (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