Compress and uncompress file archives in Terminal on Mac
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
command 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 with the .tar.gz extension. If the archive isn’t compressed, it usually just ends in .tar.
Tip: 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). See Compress or uncompress files and folders.
Create a compressed tar archive
In the Terminal app on your Mac, enter the
tar
command, then press Return.For a basic compression of a folder named, for example, LotsOfFiles, you could enter:
$ tar -czf LotsOfFiles.tgz LotsOfFiles
The
z
flag indicates that the archive is being compressed, as well as being combined into one file. You’ll usually 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
v
flag:$ tar -czvf LotsOfFiles.tgz LotsOfFiles
Uncompress a tar archive
To uncompress a tar archive on your Mac, do one of the following:
In the Terminal app on your Mac, enter the
tar
command with thex
flag, then press Return. To see progress messages, also use thev
flag. For example:$ tar -xvf LotsOfFiles.tgz
In the Finder on your Mac, double-click the tar file.