Dave's Notes

Absence of evidence is not evidence of absence

File Types

October 18, 2016

Looking into the file utility and having it detect file types.

On OS X, the various configuration files are located in /usr/share/file/magic.1

$ file -b seasurf.nc
NetCDF Data Format data

$ file -b -I seasurf.nc
application/octet-stream; charset=binary

It would be nice to augment the file command to support the various formats used in DataONE.

For xml files, like various types of metadata, detection can use regular expressions2 on namespaces. For example, part of the kml detection looks like:

0 string    \<?xml
>20  search/400 \ xmlns=
>>&0 regex ['"]http://earth.google.com/kml Google KML document
!:mime application/vnd.google-earth.kml+xml
>>>&1 string 2.0' \b, version 2.0
>>>&1 string 2.1' \b, version 2.1
>>>&1 string 2.2' \b, version 2.2
  1. https://linux.die.net/man/5/magic 

  2. https://www.mkssoftware.com/docs/man4/magic.4.asp 

File Types - October 18, 2016 - Dave Vieglais