How to check corrupt and duplicated fonts on Linux

command linefonts

I need to find software that can detect duplicate fonts out of a folder, and be able to tell if a font file is corrupted. Needs to be command line so I can script it for situations, although if you know of a GUI one that can take scripts or something of the sort that could possibly work as well.

Best Answer

I don't know how you could detect corrupt fonts but since font files are just files like any other, you can search through your directory and check for duplicate md5sums to find the duplicates.

This can be scripted fairly easily, for example, in Perl:

find /usr/share/fonts -type f -exec md5sum '{}' + | 
  perl -lane 'push @{$k{shift(@F)}, @F; 
              END{
                  map{ 
                     if($#{$k{$_}}>1){print; print for @{$k{$_}}} 
                     }keys(%k)
              }'

I created 4 duplicate fonts on my system and got this output:

/usr/share/fonts/truetype/mine/dup3.tiff
/usr/share/fonts/truetype/mine/dup1.iff
/usr/share/fonts/truetype/mine/dup2.tiff
/usr/share/fonts/truetype/mine/original.tiff

/usr/share/fonts/X11/Type1/encodings.dir
/usr/share/fonts/X11/75dpi/encodings.dir
/usr/share/fonts/X11/100dpi/encodings.dir

Still, if all you end up doing is finding duplicate files, there are far more sophisticated programs that can deal with this better and faster. See the answers here.