
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 Zip and unzip files and folders.
Create a compressed tar archive
Go to the Terminal app
on your Mac.Enter the
tarcommand, then press Return.For a basic compression of a folder named, for example, LotsOfFiles, you could enter:
% tar -czf LotsOfFiles.tgz LotsOfFilesThe
zflag indicates that the archive is being compressed, as well as being combined into one file. You 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
vflag:% tar -czvf LotsOfFiles.tgz LotsOfFiles
Uncompress a tar archive
To uncompress a tar archive on your Mac, do one of the following:
Go to the Terminal app
on your Mac, enter the tarcommand with thexflag, then press Return. To see progress messages, also use thevflag. For example:% tar -xvf LotsOfFiles.tgzIn the Finder
on your Mac, double-click the tar file.