This site contains affiliate links. If you make a purchase, we may earn a commission.

How To Zip Files Using Command Line (Multiple Ways!)



Greetings, jungle-dwellers! If big files have been driving you bananas, it’s time to zip them up. In this guide, we’ll navigate the wilds of the command line on macOS and Linux, showing you how to zip files as easily as a monkey swings from tree to tree. So, grab your bananas, and let’s get zipping!

Table of contents

How To Zip Files on macOS/Linux Using Command Line

The command line may seem as dense as a rainforest, but don’t worry, we’re here to guide you through. Here’s how to zip files on macOS and Linux:

  1. Open Terminal on Directory: Open up your file manager and find the directory where your zip archive is located. Click the three dots and click on (Open in terminal). It’s like the tree where all the magic happens.

    How To Zip Files on macOS/Linux Using Command Line: Step 3

  2. Zip the file: Use the ‘zip’ command followed by the name you want for your zipped file and the name of your file. It’s like squashing a bunch of bananas into a handy, portable snack. Here’s an example:

    zip MyFile.zip MyFile.txt

    How To Zip Files on macOS/Linux Using Command Line: Step 2 How To Zip Files on macOS/Linux Using Command Line: Step 2

How To Zip Files with More Compression

If you’re dealing with a particularly large file, or you just want to save as much space as possible, you can use the ‘-9’ option to apply the maximum compression level:

  1. Use the ‘-9’ option: After the ‘zip’ command, add ‘-9’ followed by the name you want for your zipped file and the name of your file. For example, type in terminal:

    zip -9 MyCompressedFile.zip MyLargeFile.txt

    How To Zip Files with More Compression: Step 1 How To Zip Files with More Compression: Step 1

How To Zip a Folder Recursively

If you want to zip an entire folder, including all its subfolders and files, you can use the ‘-r’ option:

  1. Use the ‘-r’ option: After the ‘zip’ command, add ‘-r’ followed by the name you want for your zipped file and the name of your folder.

    zip -r MyFolder.zip MyFolder

    How To Zip a Folder Recursively: Step 1 How To Zip a Folder Recursively: Step 1

Check out our guide on zipping folders recursively for more information.

How To Add More Files to an Existing Zip

If you’ve already created a zip file but want to add more files to it, you can use the ‘-u’ option:

  1. Use the ‘-u’ option: After the ‘zip’ command, add ‘-u’ followed by the name of your existing zipped file and the name of the file you want to add.

    zip -u MyExistingFile.zip MyAdditionalFile.txt

    How To Add More Files to an Existing Zip: Step 1 How To Add More Files to an Existing Zip: Step 1

    With these tips, you’ll be zipping files like a pro. So, keep your chin up, your tail curled, and your files zipped. Happy archiving!

How To Zip Files Without Compression

If you want to zip files without compressing them, you can use the ‘-0’ (zero) option:

  1. Use the ‘-0’ option: After the ‘zip’ command, add ‘-0’ followed by the name you want for your zipped file and the name of your file.

    zip -0 MyFile.zip MyFile.txt

    How To Zip Files Without Compression: Step 1 How To Zip Files Without Compression: Step 1

    This command will store the files without compression.

How To Create a Password-Protected Zip File Without Being Prompted

If you want to protect your zip file with a password without being prompted, you can use the ‘-P’ option:

  1. Use the ‘-P’ option: After the ‘zip’ command, add ‘-P’ followed by your password, and then the name you want for your zipped file and the name of your file.

    zip -P YourPassword MySecureFile.zip MyFile.txt

    How To Delete Files from a Zip Archive: Step 1 How To Delete Files from a Zip Archive: Step 1

    This command will create a password-protected zip file using the password ‘YourPassword’. Remember, just like a monkey hides its bananas, keep your password safe!

How To Create Split Zip Files

If you want to create a new zip file split into smaller parts, you can use the ‘-s’ option followed by the size of each part:

  1. Use the ‘-s’ option: After the ‘zip’ command, add ‘-s’ followed by the size of each part and the name you want for your zipped file and the name of your file.

    zip -s 10m MySplitFile.zip MyLargeFile.mp4

    How To Create Split Zip Files: Step 1 How To Create Split Zip Files: Step 1

    This command will create a multi-part zip file, each part being 10MB.

How To Update Files in a Zip Archive

If you want to update files in a zip archive, you can use the ‘-f’ option.

  1. Use the ‘-f’ option: After the ‘zip’ command, add ‘-f’ followed by the name of your existing zipped file.

    The -f option in the zip command is used for “freshening” an existing zip archive.

    “Freshening” means that zip will update (replace) files in the archive only if the source file has been modified more recently than the version already in the zip archive. Files in the source file list not already in the zip archive are ignored.

    Here’s an example of how to use it:

    zip -f existing_archive.zip

    In this command, existing_archive.zip is the name of the zip file you want to freshen. This command will go through the files in existing_archive.zip and update them if the corresponding file in the current directory is newer.

    Please note that the -f option will not add files to the zip archive that weren’t there in the first place. If you want to both update existing files and add new ones, you should use the -u (update) option instead.

    How To Update Files in a Zip Archive: Step 1 How To Update Files in a Zip Archive: Step 1

    This command will refresh the specified files in the zip archive.

How To Delete Files from a Zip Archive

If you want to delete files from a zip archive, you can use the ‘-d’ option:

  1. Use the ‘-d’ option: After the ‘zip’ command, add ‘-d’ followed by the name of your existing zipped file and the name of the file you want to delete. Here’s an example:

    zip -d MyExistingFile.zip MyExistingFile/FileToDelete.webp

    How To Delete Files from a Zip Archive: Step 1How To Delete Files from a Zip Archive: Step 1

    This command will delete the specified file from the zip archive.

    Remember, the command line might seem like a jungle, but with these tips, you’ll be zipping files with the best of them. So, keep your wits about you, your tail swinging, and your files neatly zipped. Happy archiving!