How to know in Linux whether a particular file is compressed or not using a command?
file command on it. It will identify compressed files, as well as other common file formats.
Note that ZIP is a common container format. E.g. EPUB and OpenDocument files are actually ZIP files with specific content. My version of
file recognises OpenDocument files - but if yours doesn't, it may say that your OpenDocument file is a ZIP file. This may not be the outcome you had in mind :).
To be pedantic, you probably don't mean "is this file compressed", like an OpenDocument, or even an image compressed as PNG or JPEG. You probably mean "is this file an archive", like ZIP, unix tar, or a single-file archive like gzip.
Usually though, you just look at the file extension, like on Windows. Like .ZIP means ZIP file, .gz means gzip. On Linux you're also likely to see .bz2 (bunzip2) and .xz (xz).
You can determine whether a file looks like a compressed format by running the
file lorem.txt lorem.txt.gz lorem.txt: ASCII text lorem.txt.gz: gzip compressed data, from Unix, last modified: Thu Feb 7 02:10:44 2013, max compression
file will just say "data" if it doesn't recognize the format. Also, it's up to you to figure out what is compressed or not (e.g. “ASCII text”, “PPM”, “WAVE audio” are uncompressed; “gzip compressed data”, “JPEG image”, “Vorbis audio” are compressed).
Another way to detect if a file looks compressed is to try to compress it. If you can't significantly reduce the size, the file is probably compressed or encrypted.
wc -c somefile gzip <somefile | wc -c