How can I find out a file's MIME type (Content-Type)?

前端 未结 5 427
遥遥无期
遥遥无期 2020-11-30 00:12

Is there a way to find out the MIME type (or is it called \"Content-Type\"?) of a file in a Linux bash script?

The reason I need it is because ImageShack appears to

相关标签:
5条回答
  • 2020-11-30 00:35

    one of the other tool (besides file) you can use is xdg-mime

    eg xdg-mime query filetype <file>

    if you have yum,

    yum install xdg-utils.noarch

    An example comparison of xdg-mime and file on a Subrip(subtitles) file

    $ xdg-mime query filetype subtitles.srt
    application/x-subrip
    
    $ file --mime-type subtitles.srt
    subtitles.srt: text/plain
    

    in the above file only show it as plain text.

    0 讨论(0)
  • 2020-11-30 00:40

    file version < 5 : file -i -b /path/to/file
    file version >=5 : file --mime-type -b /path/to/file

    0 讨论(0)
  • 2020-11-30 00:42

    file --mime works, but not --mime-type. at least for my RHEL 5.

    0 讨论(0)
  • 2020-11-30 00:45

    Try the file command with -i option.

    -i option Causes the file command to output mime type strings rather than the more traditional human readable ones. Thus it may say text/plain; charset=us-ascii rather than ASCII text.

    0 讨论(0)
  • 2020-11-30 00:48

    Use file. Examples:

    > file --mime-type image.png
    image.png: image/png
    
    > file -b --mime-type image.png
    image/png
    
    > file -i FILE_NAME
    image.png: image/png; charset=binary
    
    0 讨论(0)
提交回复
热议问题