I'm planning on downloading a bunch of images from a website that don't come with an extension, so I want to add one based on the file's content or mime-type.
file <filename> does a great job at identifying the filetype, however I need the extension.
--extension Print a slash-separated list of valid extensions for the file type found.
This is from
file's man page, but it does not seem to work:
$ file --extension test_text_file.txt test_text_file.txt: ??? $ file --extension test_png_file.png test_png_file.png: ??? $ file --extension test_gif_file.gif test_gif_file.gif: ???
It literally prints
??? for every file I pass to it, even those that already have a proper extension. All of these are valid files of their types and get recognized perfectly by
file --extension not work for me and what can I use to get a file's extension?
An idea would be to use
file --mime-type and then create a dispatch table array that maps known mime-types to their extensions, but I'd much rather have a simpler and safer solution.