How would i get the mime type of a file-handle without saving it to disk?
What i mean is a file that is not saved to disk, rather: i extracted it from an archive and plan on piping it to another script.
Say i extracted the file like this:
tar -xOzf images.tar.gz images/logo.jpg | myscript
Now inside myscript I would like to check the mime type of the file before further processing it. How would it go about this?
as some people think my comment above is helpful i post it as an answer.
the file-command is able to determine a file's mime type on the fly/when being piped. It ist able to read a file from stdin - printing the file's --mime-type briefly/in a short manner when passing -b. Considering your example you probably want to extract a single file from an archive and dertermine its file/mime type.
$ tar -xOzf foo.tar.gz file_in_archive.txt | file -b --mime-type -
text/plain
so for a simple text file extracted from an archive to stdout it could look like the example above. hope that helped. regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With