Determine rdf mime-types in bash

209 Views Asked by At

I am writing a bash script, that needs to check the different mime-types of different files. The files should support rdf4j REST API (http://docs.rdf4j.org/rest-api/#_content_types).

Normally, using file --mime-type <file> provides the correct mime type. However, when running on a .ttl file, it returns wrong: foo.ttl: text/plain instead of text/turtle

Does it exist a better way to solve this, then checking every file-ending, for each file?

1

There are 1 best solutions below

2
On

You can use an alternative to file, for instance mimetype.

At least the following example file from the wikipedia entry on .ttl is recognized as text/turtle:

$ cat test.ttl
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix ex: <http://example.org/stuff/1.0/> .

<http://www.w3.org/TR/rdf-syntax-grammar>
  dc:title "RDF/XML Syntax Specification (Revised)" ;
  ex:editor [
    ex:fullname "Dave Beckett";
    ex:homePage <http://purl.org/net/dajobe/>
  ] .
$ mimetype test.ttl 
test.ttl: text/turtle

mimetype is provided by the package perl-file-mimeinfo in arch linux and by libfile-mimeinfo-perl on debian and ubuntu.