1

Please let me know if below two statements are correct or not:

Folder /usr/share/mime/magic has a database/table that will give me what are the current possible file formats (outputs that I can get when I type the file command and follow it by a file name).

Whenever the file command output contains the word "text" it refers to something that you can read with a text viewer, and anything without "text" is some kind of binary.

  • That is one usage of file, note that depend on what do you call text files, .doc, .pdf, .epub are containing text. BTW the man page points to /usr/share/misc/magic not to /usr/share/mime/magic. – Emmanuel Aug 21 '14 at 16:36
4

Folder /usr/share/mime/magic has a database/table that will give me what are the current possible file formats (outputs that I can get when I type "file" command and follow it by a file).

Correct except that /usr/share/mime/magic is not the directory that file uses: this file is only used for the MIME type database.

From file's manpage: "The information identifying these files is read rom the compiled magic file /usr/share/file/misc/magic.mgc, or the files in the directory /usr/share/file/misc/magic if the compiled file does not exist."

And in fact, in my Arch Linux system, that file belongs to the file package.

Whenever "file" command output contains the word "text" it refers to something that you can read with a text viewer, and anything without "text" is some kind of binary.

Looks correct (I tried to find a counterexample but was unable to).

  • Where can i see all possible answers that i can get by running "file" command and following it by a filename? I want to know the data format of random files that users will provide and then based upon the data format handle/process each file differently and therefore, would like to know what are the different answers that i could get.. – user2543622 Aug 21 '14 at 16:34
  • @user2543622 You can download file's source code and within there you will find the sources of the magic file. – Renan Aug 21 '14 at 16:36
3

The location of the file database appears to installation/version-dependent. The linuxmanpages.com version of file(1) says:

FILES

/usr/share/file/magic.mgc
    Default compiled list of magic numbers
/usr/share/file/magic
    Default list of magic numbers
/usr/share/file/magic.mime.mgc
    Default compiled list of magic numbers, used to output mime types when the -i option is specified.
/usr/share/file/magic.mime
    Default list of magic numbers, used to output mime types when the -i option is specified.
/etc/magic
    Local additions to magic wisdom.

whereas, on Cygwin and Debian, file(1) says

FILES

/usr/share/misc/magic.mgc Default compiled list of magic.
/usr/share/misc/magic Directory containing default magic files.

To further confuse matters, on Debian, /usr/share/misc/magic is a symbolic link to /usr/share/file/magic, which is an empty directory, while, on Cygwin, /usr/share/file/magic is a symbolic link to /usr/share/misc/magic, which is a fairly large file (> 600K).  So I did the obvious experiment:

file /usr/share/misc/magic
/usr/share/misc/magic: Non-ISO extended-ASCII text, with overstriking

I looked at it with vi, and it looked like ASCII text (but I didn’t scrutinize all 17000 lines).  “with overstriking” seems to indicate the presence of backspaces; see

echo -e "1 =\b/ 2" | file -
/dev/stdin: ASCII text, with overstriking

so I searched /usr/share/misc/magic for backspaces, and I found two.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.