I am going to use "file" to check file type of a buch of files. I need to get it to print output file mime type without charset part.
My code:
file dog.jpeg -i Output:
dog.jpeg: image/jpeg; charset=binary What I want:
dog.jpeg: image/jpeg 02 Answers
From the man page:
-i, --mime Causes the file command to output mime type strings rather than the more traditional human readable ones. Thus it may say ‘text/plain; charset=us-ascii’ rather than “ASCII text”. --mime-type, --mime-encoding Like -i, but print only the specified element(s). So by way of example:
$ file --mime dog.jpeg dog.jpeg: image/jpeg; charset=binary $ file --mime-type dog.jpeg dog.jpeg: image/jpeg $ file --mime-encoding dog.jpeg dog.jpeg: binary So you want file --mime-type dog.jpeg.
This may not be a clean way of doing but you can utilize the cut cmd.
file dog.jpeg -i | cut --delimiter=";" --fields=1