{"id":764,"date":"2017-03-18T13:45:20","date_gmt":"2017-03-18T08:15:20","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=764"},"modified":"2017-03-29T15:05:47","modified_gmt":"2017-03-29T09:35:47","slug":"zip-and-unzip-unix-command-line","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/zip-and-unzip-unix-command-line\/","title":{"rendered":"How do you zip\/unzip on the unix command line"},"content":{"rendered":"<p><strong>Trying to zip\/unzip the unix command:<\/strong><\/p>\n<ul>\n<li>you can simply use the zip and unzip commands like,<\/li>\n<\/ul>\n<p><strong>To compress:<\/strong><\/p>\n[pastacode lang=\u201dbash\u201d manual=\u201dzip%20squash.zip%20file1%20file2%20file3%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p><strong>To zip a directory<\/strong><\/p>\n[pastacode lang=\u201dbash\u201d manual=\u201dzip%20-r%20squash.zip%20dir1%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p><strong>To uncompress:<\/strong><\/p>\n[pastacode lang=\u201dbash\u201d manual=\u201dunzip%20squash.zip%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<p>this unzips it in your current working directory.<\/p>\n<ul>\n<li>Use tar to create an uncompressed archive and either gzip or bzip2 to compress that archive.<\/li>\n<li>The corresponding gunzip and bunzip2 commands can be used to uncompress said archive, or you can just use flags on the tar command to perform the uncompression.<\/li>\n<li>If you don\u2019t have zip and unzip packages installed and you have java, you can use jar to unzip:<\/li>\n<\/ul>\n[pastacode lang=\u201dbash\u201d manual=\u201djar%20-xf%20file.zip%20%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<ul>\n<li>You can zip files up (in compressed format) with the GNU tar program:<\/li>\n<\/ul>\n<p><strong>Example:<\/strong><\/p>\n[pastacode lang=\u201dbash\u201d manual=\u201dtar%20-zcvf%20myfile.tgz%20\u2033 message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p>where<\/p>\n<ul>\n<li><strong>-c<\/strong> means \u201ccreate\u201d<\/li>\n<li><strong>-v<\/strong> means \u201cverbose\u201d (sometimes bothersome and slowing down\u2026)<\/li>\n<li><strong>-z<\/strong> means \u201cuse (GNU)zip\u201d<\/li>\n<li><strong>-f<\/strong> XYZ declares the name of the output file.<\/li>\n<li>To unzip that file, use:<\/li>\n<\/ul>\n[pastacode lang=\u201dbash\u201d manual=\u201d%20%20%20%20%20%20%20%20%20%20%20tar%20-zxvf%20myfile.tgz%20%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<ul>\n<li>That you have a tar capable of doing the compression as well as combining of files into one.<\/li>\n<li>If not, you can just use tar cvf followed by gzip (again, if available) for compression and gunzip followed by tar xvf.<\/li>\n<\/ul>\n<p>where<\/p>\n<ul>\n<li><strong>\u2013<\/strong><strong>x<\/strong> means \u201ceXtract\u201d<\/li>\n<li><strong>-v<\/strong> means \u201cverbose\u201d (sometimes bothersome and slowing down\u2026)<\/li>\n<li><strong>-z<\/strong> means \u201cuse (GNU)zip\u201d<\/li>\n<li><strong>-f<\/strong> XYZ declares the name of the output file.<\/li>\n<\/ul>\n<p><strong>Zip Command Examples in Unix \/ Linux<\/strong><\/p>\n<ul>\n<li>zip is used to compress the files to reduce file size and also used as file package utility.<\/li>\n<li>zip is available in many operating systems like unix, linux, windows etc.<\/li>\n<li>If you have a limited bandwidth between two servers and want to transfer the files faster, then zip the files and transfer.<\/li>\n<li>The syntax of zip command is:<\/li>\n<\/ul>\n[pastacode lang=\u201dbash\u201d manual=\u201dZip%20%5Boptions%5D%20zipfile%20files_list%20\u2033 message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p><b>\u00a0Zip Command Examples<\/b>:<\/p>\n<ul>\n<li>The files in my current directory are listed below:<\/li>\n<\/ul>\n[pastacode lang=\u201dbash\u201d manual=\u201ddocs%2Flinux.pdf%20docs%2Foracle.pdf%20docs%2Funix.pdf%20linux-virtual-server.bat%20unix-server.dat%20%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<ul>\n<li>Here docs is a directory which contains the files linux.pdf, unix.pdf and oracle.pdf.<\/li>\n<\/ul>\n<p><strong>The options of zip command are:<\/strong><\/p>\n<ul>\n<li>d : Removes the file from the zip archive<\/li>\n<li>-u : Updates the file in the zip archive<\/li>\n<li>-m : Deletes the original files after zipping.<\/li>\n<li>-r : Recursively zips the files in a directory<\/li>\n<li>-x : Exclude the files in creating the zip<\/li>\n<li>-v : verbose mode<\/li>\n<li>-1 : Compresses the files faster<\/li>\n<li>-9 : Compresses the files better<\/li>\n<li>-f : freshen only changed files.<\/li>\n<\/ul>\n<p><strong>zipfile \u00a0 \u00a0\u00a0<\/strong>: creates the zip file with name as zipfile.zip<br \/>\n<strong>files_list <\/strong>: list of files to be zipped.<\/p>\n<p>Examples for how to use zip command ,<\/p>\n<p>1. <strong>Creating a zip file<\/strong><\/p>\n<p>The zip command in unix or linux system creates an archive with the specified files. This is shown below:<\/p>\n[pastacode lang=\u201dbash\u201d manual=\u201d%20%20%20%20%20%20%20%20%20%20%20%20%3Ezip%20archive%20linux-virtual-server.bat%20unix-server.dat%0A%20%20%20%20%20%20%20%20%20%20%20%20%20adding%3A%20linux-virtual-server.bat%20(deflated%2080%25)%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20adding%3A%20unix-server.dat%20(deflated%2080%25)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%3E%20ls%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20wikitechy.zip%20docs%20linux-virtual-server.bat%20unix-server.dat%20%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<ul>\n<li>The above command creates the zip file with name wikitechy.zip<\/li>\n<\/ul>\n<p>2. <strong>Extracting files from zip<\/strong><\/p>\n<p>To extract files from the zip, use the unzip command in unix system. This is shown below:<\/p>\n[pastacode lang=\u201dbash\u201d manual=\u201d%20%20%20%20%20%20%20%20%20%20%20%20%20%3Eunzip%20archive.zip%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20Archive%3A%20archive.zip%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20inflating%3A%20linux-virtual-server.bat%0A%20%20%20%20%20%20%20%20%20%20%20%20%20inflating%3A%20unix-server.dat%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3E%20ls%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20archive.zip%20linux-virtual-server.bat%20unix-server.dat%20%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p>3. <strong>Removing file from a zip file<\/strong><\/p>\n<ul>\n<li>After creating a zip file, you can remove a file from the archive using the <b>-d<\/b> option.<\/li>\n<li>To remove the file unix-server.dat from the archive, run the below zip command:<\/li>\n<\/ul>\n[pastacode lang=\u201dbash\u201d manual=\u201dzip%20-d%20archive.zip%20unix-server.dat%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20deleting%3A%20unix-server.dat%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%3E%20unzip%20archive.zip%20%0A%20%20%20%20%20%20%20%20%20%20%20%20Archive%3A%20archive.zip%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20inflating%3A%20linux-virtual-server.bat%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p>4.<strong> Update existing zip file<\/strong><\/p>\n<ul>\n<li>You can update the files in already created zip file. If any of the files are modified after zipping, you can fresh the zip file with only those modified files using the -f option.<\/li>\n<\/ul>\n[pastacode lang=\u201dbash\u201d manual=\u201d%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20zip%20-f%20archive.zip%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20freshening%3A%20linux-virtual-server.bat%20(stored%200%25)%20%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<ul>\n<li>Another way is using the -u option. This option can be used to update the specified list of files or add new files to the existing zip file.<\/li>\n<\/ul>\n[pastacode lang=\u201dbash\u201d manual=\u201dzip%20-u%20archive.zip%20linux-virtual-server.bat%20temp%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20updating%3A%20linux-virtual-server.bat%20(deflated%2079%25)%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20adding%3A%20temp%20(stored%200%25)%20%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p>5.<strong> Recursively zip files in directory.<\/strong><\/p>\n<ul>\n<li>To zip a directory recursively, use the -r option with the zip command. This example is shown below<\/li>\n<\/ul>\n[pastacode lang=\u201dbash\u201d manual=\u201d%3Ezip%20-r%20dir_archive%20docs%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20adding%3A%20docs%2F%20(stored%200%25)%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20adding%3A%20docs%2Funix.pdf%20(stored%200%25)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20adding%3A%20docs%2Foracle.pdf%20(stored%200%25)%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20adding%3A%20docs%2Flinux.pdf%20(stored%200%25)%20%0A%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n[ad type=\u201dbanner\u201d]\n<p>6. <strong>Excluding files in zipping<\/strong><\/p>\n<ul>\n<li>Let say you are zipping all the files in the current directory and want to exclude some unwanted files. You can exclude these unwanted files using the -x option.<\/li>\n<\/ul>\n[pastacode lang=\u201dbash\u201d manual=\u201dzip%20exclude_archive%20*%20-x%20linux-virtual-server.bat%20%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<ul>\n<li>The above command zips all the files in the current directory except the file linux-virtual-server.bat<\/li>\n<\/ul>\n<p>7. <strong>Faster compressing<\/strong><\/p>\n<ul>\n<li>You can compress the files very fast using the -1 option with zip command. An example is shown below with and without using fast compression.<\/li>\n<\/ul>\n[pastacode lang=\u201dbash\u201d manual=\u201d%3Ezip%20-1%20fast_archive%20linux-virtual-server.bat%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20adding%3A%20linux-virtual-server.bat%20(deflated%2079%25)%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Ezip%20normal_archive%20linux-virtual-server.bat%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20adding%3A%20linux-virtual-server.bat%20(deflated%2080%25)%0A%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<ul>\n<li>If you use fast compression, the archive file created will occupy more space (size) when compared to normal compression.<\/li>\n<\/ul>\n<p>8. <strong>Better compression.<\/strong><\/p>\n<ul>\n<li>To reduce more amount of size the files occupied, you can use the -9 option with the zip command. This gives a better compression.<\/li>\n<\/ul>\n[pastacode lang=\u201dbash\u201d manual=\u201d%3Ezip%20-9%20better_archive%20linux-virtual-server.bat%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20adding%3A%20linux-virtual-server.bat%20(deflated%2081%25)%20%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n","protected":false},"excerpt":{"rendered":"<p>Trying to zip\/unzip the unix command: you can simply use the zip and unzip commands like, To compress: [pastacode lang=\u201dbash\u201d manual=\u201dzip%20squash.zip%20file1%20file2%20file3%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/] To zip a directory [pastacode lang=\u201dbash\u201d manual=\u201dzip%20-r%20squash.zip%20dir1%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/] To uncompress: [pastacode lang=\u201dbash\u201d manual=\u201dunzip%20squash.zip%0A\u201d message=\u201dbash code\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/] [ad type=\u201dbanner\u201d] this unzips it in your current working directory. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1699],"tags":[1372,1375,1380,1374,1363,1367,1379,1365,1366,1364,1381,1382,1368,1376,1377,1378,1373,1371,1370,1369],"class_list":["post-764","post","type-post","status-publish","format-standard","hentry","category-linux","tag-extract-specified-types-from-a-zip-file","tag-extracting-exe-in-unix","tag-gzip-command-in-linux","tag-how-can-i-view-files-in-zip-from-a-terminal-command-line","tag-how-to-extract-gzip-and-tar-files-on-the-command-line","tag-how-to-unzipuncompress-segmented-zip-files","tag-how-to-zip-folder-in-linux","tag-installing-zip-and-unzip","tag-linux-unzip-command-option-to-force-overwrite","tag-unix-unzip-command-ends-successfully-without-unzipping-file","tag-unix-unzip-to-directory-unix-unzip-gz","tag-unix-zip-folder","tag-unzipping-several-specific-files-out-of-many-into-a-directory-using-the-terminal","tag-zip-command-in-unix","tag-zip-command-linux","tag-zip-command-windows","tag-zip-file-has-different-size-after-copied-to-flash-drive","tag-zip-several-soundfile-formats-without-deflate","tag-zip-the-contents-of-a-directory-without-the-directory-itself","tag-zip-the-contents-of-a-folder-without-including-the-folder-itself"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=764"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/764\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}