Since macOS is based on Unix there are a number of ways to compress files and folders within the filing system using Unix based application code, below are a few options using the Terminal or command line interface (cli). The default command line application interface in macOS is the Terminal and is stored in /Applications/Utilities.
File and folder compression saves 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 zip, tar, gz, bz2, gz and dmg.
DMG – macOS Only
This one is macOSnative only – for a GUI interface use /Applications/Utilities/Disk Utility – for command line use:
hdiutil create -format UDZO -srcfolder folder_to_compress archive_name.dmg
hdiutil attach archive_name.dmg
ls -lah /Volumes/archive_name/
hdiutil eject /Volumes/archive_name/
You can also use a number of different 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
That’s the low down, the more common compression packages available will typically be covered in one of the above.
Step 1 — Using 7-Zip to Compress Files
7-Zip has a user-friendly interface, so it’s very easy to use even for novice users. In order to create an archive with 7-Zip,you’ll need to follow these simple steps:
- Open 7-Zip application.
- Access the file(s) that you want to compress. Select them (you can select multiple files by holding SHIFT key) and hit Add.A window with various settings will appear. Explanations of the main parameters:
- Archive: choose the name of your archive file.
- Archive format: choose the format of the archive. Available formats are 7z, XZ, BZIP2, GZIP, TAR, ZIP and WIM. 7zip (7z) is recommended due to its high compression rate. However, this format is has a low compatibility with other services.
- Compression level: choose how much you would like to compress the files. Compression time increases with compression level. The presets range from Store (fastest compression) to Ultra (slowest compression, most space saved).
- Split to volumes, bytes: you can split your archive into parts. This can be useful when transferring huge archives. For example, if you are trying to burn 2 GB of files to a CD, you can tell 7-Zip to split the archive every 650Mb. It will create several smaller archives. Single smaller archive will not exceed the specified size (in our situation 650MB). However, uncompressing the files will require all the smaller archives.
- Encryption: you can set a password for your archive. Then the files can be extracted with password only.
- For Compression method leave default LZMA option as it is considered to be the best.
- Once all your settings are set, click OK to create the archive. The archive file will appear in the same location as the original file(s).
Step 2 — Uncompressing files with 7-Zip
To uncompress the files, right-click on the archive and choose 7-Zip -> Extract Here option.
Files will be extracted to the same directory as the original archive.