1. Home
  2. Operating Systems
  3. How to Zip files and folders in macOS from Terminal

How to Zip files and folders in macOS from Terminal

Share

Not many people know that it is possible to use the terminal of our macOS to zip files and folders. This little trick can be useful to many developers or geeks who like to use the terminal frequently or if you just want to learn new tips.

Using Zip from Terminal

First of all, we should say that we need to use two different commands to compress and extract files. The command to compress files into an archive is zip, but if we want to extract the content of an archive we should use unzip.

If we want to Zip files and folders or UnZip an archive in macOS using the terminal you need to use the following commands:

  • Zip a file: zip archive.zip file
  • Zip a folder: zip -r archive.zip folder/
  • Unzip an archive: unzip archive.zip

Using Ditto from Terminal

The ditto command is a very strong utility tool in macOS. Unlike zip, ditto can perform different operations, including copying files and folders, merging the contents of different folders. ditto is the command that the Finder app uses under the hood.

To Zip files and directories or extract archives in macOS using the ditto command from the terminal, you can use the following commands:

  • Zip a folder: ditto -c -k --sequesterRsrc --keepParent folder archive.zip
  • Extract an archive: ditto -x -k archive.zip destination

Conclusion

In this article we have learned to use three new commands: zip, unzip and ditto (partially). We now know how to zip and unzip files and folders using the macOS terminal, and this will definitely help us to feel better at the end of this day.

In conclusion, if you want to learn more about these commands, here you will find the full documentation:

If you like our post, please share it:

Polynique © 2020 - 2021, made with ❤️ by a developer, for developers.

Latest update:

All trademarks, service marks and company names are the property of their respective owners.

AboutPrivacy PolicyCookie Policy