zip Command in Linux with Examples

Posted in

zip Command in Linux with Examples
sangeeta.gulia

Sangeeta Gulia
Last updated on April 24, 2024

    When working with large files, compressing files is a common task. The files are usually downloaded in compressed format, which is then extracted. Before sending a file to a remote, we may need to compress it. Using the zip command on Linux is simple. In this article, we'll look at the zip command and some of its most useful parameters.

    What is the ZIP command?

    zip is a Unix-based compression and file-packaging command for compressing and decompressing files. A zipped file can be found on a variety of operating systems, including Unix, Linux, and Windows. If the bandwidth between two servers is restricted and you need to transmit files quickly, we can easily compress the files and transfer them and later extract them. The zip command combines one or more compressed files with information about the files into a single archive (name, path, date, time of last modification, protection, and check information to verify file integrity).

    ZIP command in Linux

    With a single command, a whole directory structure may be compressed into a single archive. Text files often have compression ratios of 2:1 to 3:1. zip has only one compression mechanism. However, it may also store files uncompressed. For each file to be compressed, zip picks the best of the two options. The command may be used to package a group of files for distribution, archive data, and save disk space by compressing unnecessary files or directories temporarily. The syntax for the command:

    $zip [options] zipfile files_list

    1. -d option

    The -d option can be used to delete a file from a zip file after it has been created.

    $zip –d demo.zip file.c

    2. -u option

    Updates the file in the zip bundle. This option can be used to update the supplied list of files or to add new files to a zip file that already exists. Only if it has been amended more recently than the version already in the zip archive should you update an existing entry in the zip archive.

    $zip –u filename.zip demo.txt

    3. -m option

    After zipping, the original files are deleted. This really deletes the target directories/files after creating the given zip archive rather than moving them into it. If a directory becomes empty after the files are gone, the directory gets erased as well. No deletions are made until zip has successfully built the archive. This is good for saving disc space, but eliminating all input files might be risky.

    $zip –m filename.zip demo.txt

    4. -r option

    To recursively zip a directory, use the -r option with the zip command. This will recursively zip all of the files in the directory. This option allows you to compress all of the files in a given directory.

    $zip –r demo.zip directory

    5. -x option

    When executing the zip command, exclude the files using this command. Let's imagine you're zipping all of the files in the current directory but want to leave out a few that you don't want. The -x option can be used to exclude these undesired files.

    $zip –x demo.zip excluded_files

    6. -v option

    Specify whether to use verbose mode or to report diagnostic version information. This option normally allows the display of a progress indicator during compression and requests verbose diagnostic information regarding zip file structure peculiarities when used in real-world operations.

    $zip –v demo.zip file.txt

    7. -e option

    You can use the - e option to encrypt sensitive information that has to be stored in the archive.

    zip -e demo.zip directory

    Conclusion

    In this article, we went through the description of the zip command along with its various options. We saw how we could encrypt sensitive files, exclude certain files, recursively zip the files, etc., using the zip command.

    People are also reading:

    Leave a Comment on this Post

    0 Comments