How to Zip a file in Linux

In addition to being a file package utility, Zip is used to compress files to minimize file size. Numerous operating systems, including Windows, Linux, and Unix, support Zip.

One or more compressed files and their associated metadata (name, path, date, time of last modification, protection, and check information to ensure file integrity) are combined into a single zip archive by the zip program. One command can pack an entire directory structure into a zip archive.

For text files, compression ratios of 2:1 to 3:1 are typical. Zip can store files without compression and has a single compression method called deflation. With every file that needs to be compressed, zip automatically selects the better of the two. The application can be used to archive files, package a collection of files for distribution, and temporarily compress unused files or directories to free up disk space.

Typical Usage

zip [Choices] [name of file.zip] [names of files]
+D
  • Remove files from the archive (-D): You can use this option to take particular files out of a zip file. Using the -d option, you can remove files one by one after a zip file has been created.
  • Update files in the archive (-U): You can update files in an already-existing zip archive by using the -u option. To update or add new files to the archive, you can provide a list of files. Only when the updated version is more recent than the one that is already in the zip archive does the update take place.
  • Move files into the archive (-M): You can move specific files into the zip archive by using the -m option. After the zip archive is created, this operation also removes the target directories or files. A directory is also erased if, after the files are removed, it is left empty. Proceed with caution when using this option as it deletes the input files permanently.
  • Recursively zip a directory (-R): You can recursively zip a directory and its contents by using the -r option. In the resulting zip archive, it contains every file found in the designated directory and all of its subdirectories.
  • Exclude files from the zip (-X): You can prevent certain files from being included in the zip archive by using the -x option. When you want to zip every file in a directory but keep some unwanted files out, this is helpful.
  • Verbose mode (-V): The verbose mode, which provides diagnostic information during compression, is enabled by the -v option. It provides verbose diagnostic information about the zip file structure along with a progress indicator. When used independently, it prints information about the target environment and the zip executable along with a diagnostic screen.

Zipping a File in Linux Terminal

Zip will most likely be installed as a command line application, but your Linux distribution may have different GUI options—or none at all.

You should then be able to run the command on the folder if you launch a terminal console in the parent directory or navigate there from the command line using the cd command.

The syntax to zip a file is as follows:

zip -r <zip file name> <directory name>

The ‘-r’ option instructs zip to include subdirectory files and folders.

For example, to zip a folder named ‘My Files for Copyright Registration’, you can use the following command:

zip -r readyToUpload.zip 'My Files for Copyright Registration'

If the name of the zip file or folder has spaces in it, enclose it in quotes.

You can use the command unzip to extract the contents and verify that everything is as expected, for example, by running unzip myFiles.zip.

Because both the Mac and Linux operating systems are based on Unix, they function remarkably similarly. On a Mac, the same commands ought to function as well.

Linux Zip Command

For Unix, ZIP is a compression and file packaging tool.

In addition to being a file package utility, Zip is used to compress files to minimize file size.

One or more compressed files and associated metadata are combined into a single zip archive by the zip utility.

For text files, compression ratios of 2:1 to 3:1 are typical.

You can remove specific files from a zip archive by using the -D option.

You can update files in an existing zip archive by using the -U option.

You can transfer specific files into the zip archive by using the -M option.

Zipping a File in Unix

Zip is a Unix tool for compressing and packaging files.

Every file is kept in a single file, denoted by the extension.zip {.zip-filename} plus the file contents.

Zip is used to compress files in order to reduce file size.

Multiple compressed files can be stored in a single zip archive with details about the files, such as their name, protection, path, date, and last modification time, all of which can be checked for file integrity using a zip program.

The application is useful for archiving files by temporarily compressing unused directories and files, packing a file’s group for distribution, and saving disk space.

For different types of text files, compression ratios of 3:1 and 2:1 are typical.

Zip has a single compression technique (deflation) and can also store multiple files uncompressed.