Psychz - Jessica
Votes: 0Posted On: Nov 09, 2021 12:22:50
ZIP is a highly useful archive file format that helps in storage and file management. It can save a lot of lot of space and network bandwidth. With an efficient zipping utility, you can compress and store files on your drive or share multiple files and folders by combining them into one single file.
Before we learn how to zip a file/files (multiple) or directories, let us see how to install it on the system. Most of the time, you won't find the zip utility installed on your Linux system by default.
To install zip, you can use your distribution's default package manager.
Ubuntu and Debian:
# apt install zip
CentOS and Fedora
# yum install zip
Let us now see how to compress file/files or directory/directories using ZIP tool.
Use the 'zip' command followed by the name you want to give to the zip file followed by the name of the file you want to zip.
# zip my_zip_file.zip filename1
The output will generate a compressed file by the name 'my_zip_file.zip' which will hold information of file 'filename1'.
Note: In the above example, if the my_zip_file name doesn’t end with .zip, the extension is added automatically.
To zip one or more files, specify the files you want to add to the archive separated by space, as shown below:
# zip my_zip_file.zip filename1 filename2 filename3
The above command will combine and compress all the three files 'filename1 filename2 filename3' into one zip file 'my_zip_file.zip'.
Often, you’ll create a zip archive of a directory including the content of subdirectories. The '-r' option allows you to traverse the whole directory structure recursively:
# zip -r my_directory.zip directory_name
You can also add multiple files and directories in the same archive:
# zip -r my_directory.zip directory_name1 directory_name2 file1 file1
Zip utility is pretty simple to use and can be used using GUI as well. We hope that you find the information above helpful.