# how to check if file is zipped

**URL:** <https://community.unix.com/t/how-to-check-if-file-is-zipped/169576>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [March 6, 2007, 5:35pm UTC](https://community.unix.com/t/how-to-check-if-file-is-zipped/169576 "2007-03-06T17:35:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![arushunter](https://community.unix.com/letter_avatar/arushunter/32/6_22734026db12803ebb3e059622ac3534.png) [@arushunter](https://community.unix.com/u/arushunter)\
**Post date:** [March 6, 2007, 5:35pm UTC](https://community.unix.com/t/how-to-check-if-file-is-zipped/169576/1 "2007-03-06T17:35:34Z")

</div>

I have a script that grabs files from directory , zips and moves them somewhere else. It works fine except the case when files it grabs are already zipped. Then it trys to zip it again which does not make sence.

How can I check before zipping if file is already zipped?  
thanks in advance

---

<div class="post-metadata">

**Author:** ![BOFH](https://community.unix.com/letter_avatar/bofh/32/6_22734026db12803ebb3e059622ac3534.png) [@BOFH](https://community.unix.com/u/BOFH)\
**Post date:** [March 6, 2007, 8:34pm UTC](https://community.unix.com/t/how-to-check-if-file-is-zipped/169576/2 "2007-03-06T20:34:03Z")

</div>

```nohighlight
$ file tztest.gz
tztest.gz: gzip compressed data - deflate method , original file name , max compression

```

Carl

---

<div class="post-metadata">

**Author:** ![dennis.jacob](https://community.unix.com/user_avatar/community.unix.com/dennis.jacob/32/798_2.png) [@dennis.jacob](https://community.unix.com/u/dennis.jacob)\
**Post date:** [March 6, 2007, 10:56pm UTC](https://community.unix.com/t/how-to-check-if-file-is-zipped/169576/3 "2007-03-06T22:56:56Z")

</div>

You can also use the below gzip options to verify that file is compressed.

-l option will give you the details of compression.  
-t will check the integrity of the zipped file

You can incorporate the same in the script something like below:

gzip -t file 2\>/dev/null  
[[$? -eq 0]]&&echo "Compessed file" || echo "Not compressed"

---

<div class="post-metadata">

**Author:** ![arushunter](https://community.unix.com/letter_avatar/arushunter/32/6_22734026db12803ebb3e059622ac3534.png) [@arushunter](https://community.unix.com/u/arushunter)\
**Post date:** [March 7, 2007, 11:38am UTC](https://community.unix.com/t/how-to-check-if-file-is-zipped/169576/4 "2007-03-07T11:38:11Z")

</div>

thank you. it worked
