I recently wrote a script to watermark all of the image files in a directory. Most of the images I use on this website are PNG files, but I occasionally use JPGs. The challenge in my script was to find all of the image files in the directory regardless of image type.
After a bit of web research I discovered the file
command. The file
command takes a list of files as input and outputs the file names along with file type.
For example, to see the file types of the files in your home directory, open a terminal and enter:
To see the file types expressed as MIME types enter:
For my image watermarking script I pipelined the output to the grep command like this to find all of the image files.
The great thing about this command is that it will find all of your desired files regardless of file extension. For example, if you renamed a bunch of JPGs to eliminate the .jpg extension, you could still find all of them with
#
Just what i was looking for... thanks a lot