{"id":2853,"date":"2018-03-15T13:20:57","date_gmt":"2018-03-15T13:20:57","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=2853"},"modified":"2018-03-15T13:20:57","modified_gmt":"2018-03-15T13:20:57","slug":"how-to-compress-and-uncompress-files-and-folders-in-the-terminal-in-macos","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=2853","title":{"rendered":"How to compress and uncompress files and folders in the Terminal in macOS"},"content":{"rendered":"<p>Since macOS\u00a0is based on Unix there are a number of ways to <strong>compress files and folders <\/strong>within the filing system using Unix based application code, below are a few options using the <strong>Terminal<\/strong> or <em>command line interface (cli)<\/em>. The default command line application interface in macOS\u00a0is the\u00a0<strong>Terminal<\/strong> and is stored in <strong><em>\/Applications\/Utilities<\/em><\/strong>.<\/p>\n<p>File\u00a0and folder\u00a0compression\u00a0saves on file size and ensures the contents are captured and delivered or stored as one monolithic file. A compressed file which contains files and folders is generally referred to as an archive. Here are some built in compression applications you can use including <em>zip, tar, gz, bz2, gz <\/em>and<em> dmg<\/em>.<\/p>\n<h2><strong>ZIP \u2013 Cross Platform<\/strong><\/h2>\n<p>First up is ZIP one of the most commonly used compression techniques used across all platforms<\/p>\n<p>To compress<\/p>\n<pre class=\"crayon:false cli\">zip -r archive_name.zip folder_to_compress<\/pre>\n<p>To extract<\/p>\n<pre class=\"crayon:false cli\">unzip archive_name.zip<\/pre>\n<p>If you want to make a zip without those invisible Mac resource files such as \u201c_MACOSX\u201d or \u201c._Filename\u201d and .ds store files, use the \u201c-X\u201d option in the command so:<\/p>\n<pre class=\"crayon:false cli\">zip -r -X archive_name.zip folder_to_compress<\/pre>\n<h2><strong>TAR.GZ \u2013 Cross Platform<\/strong><\/h2>\n<p>Second up is TAR, an old favourite on Unix\/Linux \u2013 you add the GZ for the compression \u2013 compresses <em>tighter<\/em>than zip<\/p>\n<p>To compress<\/p>\n<pre class=\"crayon:false cli\">tar -zcvf archive_name.tar.gz folder_to_compress<\/pre>\n<p>To extract<\/p>\n<pre class=\"crayon:false cli\">tar -zxvf archive_name.tar.gz<\/pre>\n<h2><strong>TAR.BZ2 \u2013 Cross Platform<\/strong><\/h2>\n<p>A variation on TAR GZ but with <strong>better<\/strong> compression than both tar.gz and zip.<\/p>\n<p>To compress<\/p>\n<pre class=\"crayon:false cli\">tar -jcvf archive_name.tar.bz2 folder_to_compress<\/pre>\n<p>To extract<\/p>\n<pre class=\"crayon:false cli\">tar -jxvf archive_name.tar.bz2<\/pre>\n<h2><strong>GZ<\/strong><\/h2>\n<p>Without the tar<\/p>\n<p>To extract<\/p>\n<pre class=\"crayon:false cli\">gunzip archivename.gz<\/pre>\n<h2><\/h2>\n<h2><strong>DMG \u2013 macOS\u00a0Only<\/strong><\/h2>\n<p>This one is macOSnative only \u2013 for a GUI interface use \/Applications\/Utilities\/Disk Utility \u2013 for command line use:<\/p>\n<p><strong>To create<\/strong><\/p>\n<pre class=\"crayon:false cli\">hdiutil create -format UDZO -srcfolder folder_to_compress archive_name.dmg<\/pre>\n<p><strong>To mount<\/strong><\/p>\n<pre class=\"crayon:false cli\">hdiutil attach archive_name.dmg<\/pre>\n<p><strong>To view<\/strong><\/p>\n<pre class=\"crayon:false cli\">ls -lah \/Volumes\/archive_name\/<\/pre>\n<p><strong>To Eject<\/strong><\/p>\n<pre class=\"crayon:false cli\">hdiutil eject \/Volumes\/archive_name\/<\/pre>\n<p>You can also use a number of different formats for creating a .dmg<\/p>\n<ul>\n<li>UDZO \u2013 Compressed image (default)<\/li>\n<li>UDRO \u2013 Read only image<\/li>\n<li>UDBZ \u2013 Better compressed image<\/li>\n<li>UDRW \u2013 Read\/Write image<\/li>\n<li>UDTO \u2013 DVD disk image<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Since macOS\u00a0is based on Unix there are a number of ways to compress files and folders within the filing system using Unix [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2853","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2853","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2853"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2853\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}