bash - 在 bash 中确定 rdf mime 类型

标签 bash unix rdf rdf4j

我正在编写一个 bash 脚本,它需要检查不同文件的不同 mime 类型。这些文件应该支持 rdf4j REST API ( http://docs.rdf4j.org/rest-api/#_content_types )。

通常,使用 file --mime-type <file>提供正确的 MIME 类型。但是,在 .ttl 文件上运行时,它会返回错误: foo.ttl: text/plain而不是 text/turtle

是否存在更好的方法来解决这个问题,然后检查每个文件的每个文件结尾?

最佳答案

您可以使用 file 的替代方法,例如 mimetype

至少 .ttl 上的维基百科条目中的以下示例文件被识别为 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 在 arch linux 中由 perl-file-mimeinfo 包提供,在 debian 和 ubuntu 中由 libfile-mimeinfo-perl 提供。

关于bash - 在 bash 中确定 rdf mime 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53259541/

相关文章:

linux - bash 中使用的 -ex 选项是什么 | #!/bin/bash -ex 意思

bash - 使用 bash 将单行输入传递给命令的标准输入的最佳实践

linux - 管道 Perl 脚本输出到 head -n 10 在打印 10 行后杀死脚本

linux - 在 Linux 中运行 Bash 脚本时出现问题。

rdf - Jena RIOT 中的 JSON-LD?

linux - grep 使用另一个命令的输出

java - 使用 Java 运行 Shell 命令会出现问题

python - 替换部分 fasta header

rdf - 获取 DBPedia 信息框类别

java - 如何使用 Jena 处理 DBpedia 页面的 rdf 版本?