I have several thousands of automatically saved web-pages, proceeding from different sources. Many of the web-pages have embedded fonts in files like *.woff, *.eot, *.ttf, and *.svg. I'd like to reduce the size of these, deleting all font files. How can I test whether a file is for fonts? It's clear that I can find some with find . -type f -name *woff. Specially, confusion is possible with *svg files. A *svg file can be either a font file like xxxwebfontsxxx.svg or it can be a perfectly informative image.

If it's not possible to test the files directly, what extensions should I delete? The font files that I know by extension are *otf, *ttf, *eot, *woff and some *svg can be fonts or not. Is it save to delete these first four types of file?

  • Depending on why you want to store them, it may be interesting to know that support in browsers is declining and if a browser understands neither ttf/otf nor eot, it likely doesn't support webfonts at all. Mar 15, 2015 at 7:01

1 Answer 1


There's a command called file that makes (good but not always perfect) guesses about the file type. One way to use that command could be:

find your_web_pages_directory -type f -name "*.*" -print0 |
  xargs -0 file |
    awk 'BEGIN{FS=": +"}$2~/[Ff]ont/{print $1}' |
      xargs rm --

The find command looks for ordinary files with extensions (you may restrict that extension further if you like), the awk program matches the guess from the preceding guess by file and prints the filename, and finally the result is removed. Depending on what files you have in "your_web_pages_directory" it may be advisable to first inspect the output of the find | xargs pipeline before you add the awk and rm parts of the pipeline.

Note: The code assumes that file will report anything like "Font" or "font" for the desired files. If that is not the actual diagnostic string you'd have to change that accordingly. Make some tests on files where you know they are of the type you are searching.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.