Introduction
The zip command is one of the most used tools in Linux systems to pack and compress files. Its popularity is due to the ability to create .zip files that can be read in both Linux and Windows and macOS, ensuring compatibility between platforms. In this article you will learn to use zip effectively, creating files that maintain data integrity and avoid problems by uncompressing them in other systems.
What is the zip command?
The zip command belongs to the compression utilities family and belongs to the package called zip (and its unzip counterpart to decompress). It was originally developed by Jean-loup Gailly and Mark Adler, and remains one of the simplest ways to group several files and directories into a single compressed container. Unlike formats like tar.gz, zip stores each file with its own compression table, allowing access to individual members without the need to uncompress the entire file.
Installation
In most Linux distributions, the zip package is already pre-installed, but if it is not present you can easily install it using the package manager on your disk. In Debian / Ubuntu: sudo apt-get update & & sudo apt-get install zip. In Fedora: sudo dnf install zip. In Arch Linux: sudo pacman -S zip. After installation, check that the command is available by running zip-version, which will show the version number and the compilation date.
Create a basic zip file
The simplest syntax of the zip command is: zip name _ of the _ archivo.zip file 1 file / 2 directory. This order compresses the specified elements and saves the result in the name _ of _ archivo.zip. If you want to include a full directory and all its subdirectories, use the -r (recursive) option: zip -r copia.zip project /. The command will display, by default, a list of the files you are adding and the degree of compression achieved. To delete that output and get only error messages, add the -q (quiet) option.
Useful options for compatibility
To ensure that the resulting zip file is fully legible in other operating systems, it is recommended to combine some options that control the way data and metadata are stored. The most useful ones are presented below:
- -r: recursively includes all subdirectories and files within a folder.
- -l: converts the LF line ends to CR-LF, which improves legibility in Windows.
- -X: excludes extra attributes from the file system (such as extended permissions) that are not recognized on other platforms.
- -0: store files without applying compression (store mode), useful when the speed is priority or when you already have compressed files.
- -9: apply maximum compression level, reducing maximum size.
- -j: removes route information, saving only the file name, which prevents absolute routes that can cause confusion in other systems.
- -q: silent mode, removes the information output and shows only errors.
Practical examples
Imagine you have a folder called a project with several code files and subfolders. To create a zip compatible with Windows and macOS you can run:
zip -r -l -X projecto.zip project /
This command includes the project folder recursively, converts the endings from line to Windows format and eliminates extra attributes. If you just need to compress a couple of documents without worrying about the folder structure, use:
zip -j documento.zip informe.pdf notas.txt
In case you want a file without compression to transfer it quickly and then uncompress it on another computer, combine the -0 option:
zip -r -0 copia.zip copy /
Finally, if you want to create a password-protected zip (although the traditional zip encryption is weak, it serves light cases) you can use the -e:
zip -r -e seguro.zip confidential /
Tips to avoid problems
- Always check the contents of the zip with unzip -l before sending it to another user.
- Avoid using absolute routes when creating the zip; prefer relative routes or the -j option to remove the route information.
- If you are sharing the zip with Windows users, remember to activate the -l option to convert the line ends.
- Do not trust the traditional zip encryption for sensitive data; consider using gpg or openssl for real protection.
- Keep the zip package up to date in your system to benefit from security improvements and corrections.
Conclusion
The zip command remains a fast and reliable solution to pack files in Linux, especially when multiplatform compatibility is needed. Knowing the right options like -r, -l, -X and -j, you can create zip files that are easily opened in any operating system. Practice the examples shown and adapt the commands to your workflows to make the most of this classic tool.


