Unix Commands to check a file is compressed or not?

Hi,

I need to find out whether a file is compressed or not and based on that i need to compress that file and move it to archive folder.

say for e.g:

If file is compressed then
just move to archive folder
else
compress and move
end if

i have implemented a logic wherein i am checking for the last character in the file to be 'Z', if it is 'Z' i am not compressing it again and just moving the file or else i am compressing and moving the file. This is working fine in some cases but i want to know whether there is any command to find out whether a file is compressed or not.

Please provide some pointers on this.

Thanks & Regards,
Kiran

file is the command which can show the file type.

When you give "file <FILENAME>", that will show the what type of compression also...

$ file test.gz 
test.gz: gzip compressed data, from Unix

There could be better ways to use it inside programs.

It depends: the file command on Solaris and Linux will tell you if a file is compressed with either zip, gzip, or compress. On HPUX 10.2 the file command could not do that.

Try the "file" command

> file ./data//logs/91042131.log.gz
./data/logs/91042131.log.gz:     gzip compressed data - deflate method , original file name , max compression