How can I tell if a file is zipped or not?

SunOS xxxxxx 5.10 Generic_142900-15 sun4v sparc SUNW,T5240

We receive files that are sometimes zipped, but the file may not have the .gz or other extention that would indicated that the file is zipped. Is there a unix "test" command that I could use or something similar?

Thanks in advance

use the unix file command. see the man page

Thanks....checking it out now.

---------- Post updated at 07:29 PM ---------- Previous update was at 07:16 PM ----------

I was hoping to use it in a script. I guess I could grep for the work "deflate" any other options?

Something like this perhaps :

file $1 | grep -i gzip
case $? in
0)
	printf "GZ archive is matched \n"
	gzip -d $1 ## or whaeva you need to do here
;;
1) 
	printf  "Not matched \n"
	## code here
;;
esac

You run the script as ./script.sh <fileforchecking>
Or make it a function in shell and run loops against it.

Regards.

Thanks. Sorry for the delay. I normally work the night shift. Thanks again for the help.

A simpler way to accomplish that same task is to use the exit status directly in an if statement:

if file "$1" | grep -iq gzip; then
	printf "GZ archive is matched \n"
	gzip -d "$1" ## or whaeva you need to do here
else
	printf  "Not matched \n"
	## code here
fi

Yes, but with case statement you have wider control over $?, don't you agree ?

For instance, if you get return "2" from grep (unsupported switch in grep for instance)
you can handle it more transparent in case statement like :

2) printf "Unsupported, please check man grep $(grep --help)"

If you're interested in more than whether or not the exit status was 0, then, sure, using a case statement with $? is best.