Sei sulla pagina 1di 12

Compress les & folder in Terminal Command Lin...

http://coolestguidesontheplanet.com/how-to-comp...

COOLEST GUIDES ON THE PLANET


Neil Gee

Search the planet...

HOME
ALL POSTS

OS X

WORDPRESS

WEBDEV

SEO

IOS

CONTACT

How to compress and uncompress files


and folders in OSX 10.10 Yosemite using
Terminal
March 19, 2014 15 Comments

1 of 12

30/04/2015 10:02

Compress les & folder in Terminal Command Lin...

http://coolestguidesontheplanet.com/how-to-comp...

zip-tar-dmg-osxcompress-formats[/caption]
Since OSX is based on Unix there are a of ways to compress files and folders, below are a
few options using the command line interface. The default command line application
interface in OSX is the Terminal and stored in /Applications/Utilities.
We should always compress files and folders to save on file size and ensure 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.

ZIP Cross Platform


First up is ZIP one of the most commonly used compression techniques used across all
platforms
To compress

zip -r archive_name.zip folder_to_compress

2 of 12

30/04/2015 10:02

Compress les & folder in Terminal Command Lin...

http://coolestguidesontheplanet.com/how-to-comp...

To extract

unzip archive_name.zip

If you want to make a zip without those invisible Mac resource files such as _MACOSX or
._Filename and .ds store files, use the -X option in the command so:

zip -r -X archive_name.zip folder_to_compress

TAR.GZ Cross Platform


Second up is TAR, an old favourite on Unix/Linux you add the GZ for the compression
compresses tighter than zip
To compress

tar -zcvf archive_name.tar.gz folder_to_compress

To extract

tar -zxvf archive_name.tar.gz

TAR.BZ2 Cross Platform


A variation on TAR GZ but with better compression than both tar.gz and zip.
To compress

3 of 12

30/04/2015 10:02

Compress les & folder in Terminal Command Lin...

http://coolestguidesontheplanet.com/how-to-comp...

tar -jcvf archive_name.tar.bz2 folder_to_compress

To extract

tar -jxvf archive_name.tar.bz2

GZ
Without the tar
To extract

gunzip archivename.gz

DMG OSX Only


This one is Mac OSX native only for a GUI interface use /Applications/Utilities/Disk Utility
for command line use:
To create

hdiutil create -format UDZO -srcfolder folder_to_compress


archive_name.dmg

To mount

hdiutil attach archive_name.dmg

4 of 12

30/04/2015 10:02

Compress les & folder in Terminal Command Lin...

http://coolestguidesontheplanet.com/how-to-comp...

To view

ls -lah /Volumes/archive_name/

To Eject

hdiutil eject /Volumes/archive_name/

You can also use a number of dierent formats for creating a .dmg
UDZO Compressed image (default)
UDRO Read only image
UDBZ Better compressed image
UDRW Read/Write image
UDTO DVD disk image

Like

Tweet

Related

5 of 12

30/04/2015 10:02

Compress les & folder in Terminal Command Lin...

http://coolestguidesontheplanet.com/how-to-comp...

Cats: OS X, Tech
Tags: compress, OSX, tar, zip

6 of 12

30/04/2015 10:02

Compress les & folder in Terminal Command Lin...

15 Comments

http://coolestguidesontheplanet.com/how-to-comp...

Coolest Guides on the Planet

Share

Recommend 1

Login

Sort by Newest

Join the discussion


Niall Mac Giolla Rua

3 months ago

Hi. Is creating DMGs better for compression than tar files?


Reply Share

Neil Gee

Mod > Niall Mac Giolla Rua 3 months ago

No tar is better
Reply Share

Niall Mac Giolla Rua > Neil Gee

3 months ago

Thank you!
Reply Share

Billy Romano III

5 months ago

So this isn't working in Mac OS X Yosemite. Awesome. Another bug with the new operating system...
Since Yosemite is a princess, it requires the 'sudo' user command prepended to fix this issue. If not, it will
throw this error: tar: Failed to open 'archive_name.tar.gz'
Edit:
nevermind. It was an issue with the CHOWN of my folder being set to _www, instead of my user
account... : D
Reply Share

Kourasmenos Tempelaros

a year ago

Is it possible to split the files also?


Reply Share

1
Pawe P.

a year ago

Thanks!
Reply Share

dek

a year ago

this really is a very helpful article. all other guides on the web only explain the .zip way. but tar is a lot
better.
Reply Share

Chris M

2 years ago

Shouldn't tar -jcvf archive_name.tar.bz2 folder_to_compress be :


tar -jxvf archive_name.tar.bz2 to uncompress?
7 of 12

30/04/2015 10:02

Compress les & folder in Terminal Command Lin...

http://coolestguidesontheplanet.com/how-to-comp...


Subscribe to the
Latest Posts
Add in your email address...
Keep Me Posted!

Find us on Facebook

Coolest Guides on the Planet


Like

Coolest Guides on the Planet shared a


link.
March 31 at 2:59am

Overview of
how JQuery
selects HTML
elements on the
page
Coolestguidesontheplan
COOLEST
GUIDES
et.com | Neil Gee
Like

Comment

Share

1,084 people like Coolest Guides on the Planet.

Facebook social plugin

8 of 12

30/04/2015 10:02

Compress les & folder in Terminal Command Lin...

http://coolestguidesontheplanet.com/how-to-comp...

LATEST

POPULAR

COMMENTS

Overview of how JQuery selects HTML


elements on the page
Connecting SSH with no Passwords from
Local to Live Domain
Install WordPress Dev Sites on Vagrant with
Variable VVV
Using ScrollReveal.js in a WordPress Genesis
Theme
Make a passwordless SSH Connection
between OSX 10.10 Yosemite and Linux Server

Overview of how JQuery


selects HTML elements
on the page
March 31, 2015

Connecting SSH with no


Passwords from Local
to Live Domain
March 26, 2015

9 of 12

30/04/2015 10:02

Compress les & folder in Terminal Command Lin...

http://coolestguidesontheplanet.com/how-to-comp...

Install WordPress Dev


Sites on Vagrant with
Variable VVV
January 24, 2015

Using ScrollReveal.js in
a WordPress Genesis
Theme
November 6, 2014

Make a passwordless
SSH Connection
between OSX 10.10
Yosemite and Linux
Server
October 27, 2014

Turn off AutoCorrect on


OSX 10.10 Yosemite for
all Applications
October 21, 2014

Install and Configure


wget on OS X Yosemite
10.10 and fix SSL
GNUTLS error
October 20, 2014

10 of 12

30/04/2015 10:02

Compress les & folder in Terminal Command Lin...

http://coolestguidesontheplanet.com/how-to-comp...

Tags
10.6 apache

backup baseband Bing boot

Coolest

Guy on the Planet Coolest Guy Planet cpanel


css custom database drupal error Firmware

genesis Google image instadmg ios


iphone jailbreak keys Keywords lion mac mysql

OSX PageRank php private Rank Rank Checker ranking


redirect rsa

SEO SERPS shell ssh terminal Twitter

unstoppables

11 of 12

WordPress Yahoo

30/04/2015 10:02

Compress les & folder in Terminal Command Lin...

http://coolestguidesontheplanet.com/how-to-comp...

Copyright 2015 Neil Gee - All Rights Reserved! Powered by CGP - Hosted by Servint

12 of 12

30/04/2015 10:02

Potrebbero piacerti anche