How to Zip File/ Folder in Linux? – ZIP command in Linux

by robin

Working as a developer can be a lot challenging. There will be folders loaded with files. You might have to transfer the folder or store it efficiently in some situations. Archiving the folder into a .zip file will be the most efficient way. Doubtless, it is common in Linux systems to come across compressed tar files, but zip archives are a viable choice. But if you don’t know how to use a Linux zip folder or archive file, then the guide is here to help.

The details will help you know how to compress a folder on the Linux distributions. You will be able to understand things in detail. So when you wish to continue with the process, it will be easy for you.

Understanding Linux Zip Files

Zip is the most widely used archive file format. It supports lossless data compression. Thus, the folder will be like a data container that will include more than one compressed file or directory. The compressed file here will take up less space, and transferring from 1 to another machine will be easy. Thus, file extraction from Linux, Windows, or macOS will be available.

linux zip folder

Zip is the command line utility that will help create the archives. The syntax form for the command will be: zip OPTIONS ARCHIVE_NAME FILES

The users must write permission to create a zip archive in a specific directory. Remember, zip files do not support the Linux style ownership information. The extracted files are of the users who run the command to preserve the file ownership and the permission one needs to use the tar command.

Also, one needs to understand that Linux zip folder utility is not installed by default in most Linux distributions. But you can install it using a distribution package manager.

Also Read: How to List Drives/ Disks in Linux? (Beginner’s Guide)

How does the Zipping Process Work?

Once you use the linux zip folder command, the utility will start scanning out the files mentioned in the input. If the scan takes more than 5 seconds, the zip command will display the message scanning files.

The file processing is complete when the output displays dots at 2 seconds. When the time-lapse is more than 2 seconds, it would mean the command takes longer to locate the files, or the internet connection is slow. When zip cannot find a specific file, it will issue a warning but will continue to process your request.

Finally, in some cases, the files are scannable during the process. The command will issue a warning at the end informing you about the left files and the number of the processed ones.

Using the Linux zip folder function will save a lot of space on your device. You will also have the convenience of keeping the files separated easily. But you need to understand and use the command correctly for better results.

Zipping a Folder from Linux Command Line

You can use the Linux zip folder command syntax with the -r (recursive) option when you need to archive a folder from the command line. The content and the folder will be output to the terminal. And this is the confirmation that the utility is now compressed and archived.

You can even choose to specify relative parts to files. Also, you can specify directories in the command or choose to include division files. All the required folders or files can easily be compressed into a single linux zip folder archive.

Also Read: How to copy directory using a command on Linux?

Compression Methods and Level

You will find deflate as the default compression method. When the linux zip folder utility determines that the file isn’t suitable for compression, it will store the file in the archive without compressing it using the store method. Generally, in Linux distributions, the utility also supports the bzip2 compression method.

You will have to use the -z option to specify a compression method. With this, the command will allow you to compress a number prefix with the dash from 0 to 9. The default compression level is -6. But, when you use -zero, all the files will be stored without compression. In contrast, -9 will force the zip command to use optimal compression for all the files.

Simply put, when there is a higher compression level, the zip process will be more CPU intensive. It will take a lot more time to complete.

Zip a Folder Using Find

To zip a folder with an unknown part, you can use the find command easily. For this, you will have to find the exec command. Thus, it will be easy for you to execute the zip command for creating an archive. Now to zip the folders present in the current directory, you will have to run the command:

find. –maxdepth 1 type d –exec zip archive. Zip {} +

Using this command will be pretty helpful for you to get the flexibility for choosing the folders quickly. You also can choose to have a certain level of folders zipped into your archive.

Zip a Folder from GNOME GUI

If you wish to use the Linux exit folder correctly, then here are the steps for the same.

  • Use GNOME’s file browser to quickly navigate to the folder you wish to zip.
  • Now, you must right-click on the folder and select the option compress.
  • On the next menu, you will find .zip. You must select it and type the name you wish to give to the zip file.
  • Finally, you need to click on the create option.

Once done, you will see a linux zip folder archive created in the same directory where your folder is present.

Frequently Asked Questions

How many types of the zip is in Linux?

As of now, zip supports two distinct types of command modes, including external and internal. The external module is responsible for reading the files from the file system. At the same time, the internal mode is responsible for operating only on the entries in the existing archive.

What is the use of zip in Linux?

Zip helps compress files to reduce their size and can also be used as a file package utility. Zip can be available for many operating systems like Linux, Windows, etc. If you have limited bandwidth between two sources and wish to transfer the files faster, you can compress them and send them.

What is the best way to zip a folder in Linux?

The best way to zip a folder on Linux is to use the zip command. You must use it along with the “-r” option and specify the file you wish to archive and the folder to be added to the zip file. You can also be specific about multiple folders if you want to have multiple directories compressed in the zip file.

Conclusion

Zip command is quite easy to use, keeping in mind other utilities in the Linux ecosystem. The guide provided a straightforward way to complete the Linux zip folder process. But the alternate method of using the terminal is easy as well. When you master the correct command to make the necessary changes, the process is fast. Once you understand how to use the Linux zip folder process, you can save a lot of storage space.

You may also like

Leave a Comment