Compress and uncompress file archives
When sending folders and multiple files between computers, it’s helpful to compress them into a single archive. This saves space, lets you transfer just one item instead of many, and makes it easier to resume in case the task is suspended for some reason.
In Terminal, you can use the GNU
tar tool to compress and uncompress files and folders.
The usual file extension for a compressed tar archive is .tgz, although you might also see files ending in .tar.gz. If the archive isn’t compressed, it usually just ends in .tar.
Note: It’s easier to compress or uncompress files directly in the Finder (it’s recommended that you use the
tar command in Terminal only if you specifically need to create a tar archive). For more information, see Compress or uncompress files and folders in Mac Help.
Create a tar archive
For a basic compression of a folder named, for example, “LotsOfFiles,” you could enter:
$ tar -czf LotsOfFiles.tgz LotsOfFiles
zflag indicates that the archive is being compressed, as well as being combined into one file. Usually you’ll use this option, but you aren’t required to.
If it’s a large folder, you may want to monitor the process by adding the
$ tar -czvf LotsOfFiles.tgz LotsOfFiles
Uncompress a tar archive
To uncompress a tar archive, use the
tarcommand with the
xflag. To see progress messages, also use the
vflag, as shown in this example:
$ tar -xvf LotsOfFiles.tgz
You can also uncompress tar archives in the Finder by double-clicking them.
tar tool has many options. For more information about the
tar tool, see its man page.