I have a simple question here. I have a file and want to check if it is gzipped or not. I've had cases where people rename files without .gz so I'm using file $name instead of looking for ".gz" in the filename. The output of file $filname gives a long string: zip1.gz: gzip compressed data, was "zip1", from Unix, last modified: Fri Jan 26 11:01:59 2024.
I have two commands that appear to both work.
if file $filename | grep -q gzip ; then
if [[ $(file $filename) == *"gzip"* ]] ; then
Which way is preferred?
I also don't know why the first method works. file $filename outputs a string, correct? Then that string is piped to the input of grep. I thought grep accepts a file as an input, not a string.
What I would do:
or
Both solutions don't need bash, you even can use posix
shwith them.