A commonly used archive file format for files and folders is known as Zip. Files can be compressed into archived formats to save disk space and network bandwidth. Zip files can be easily extracted in Windows, Linux, and MacOS operating systems.
This blog post will demonstrate how to zip a file in a linux terminal.
How To Zip a File in Linux Terminal?
In Linux, we can use the zip command to compress the files into ZIP format.
First, let’s create some text files in our system using the command:
$ touch file{1.5}.txt

It can be seen that five text files have been created
Now zip the above files using the below-listed command:
$ zip files filenames

It can be seen that the five files are zipped successfully.
To see the contents of a zip file, use the following command:
$zip -sf files.zip
It can be seen that the five text files are displayed.

Let’s see the zip files on our system.
Simply click on Files icon.

It can be seen that the zipped files are present in our system.

How To Add a Directory to a Zip File
We can also add a folder or a directory to our zip file. Use the following command to do so.
$ zip -r files directoryname
In our scenario, we will add the documents folder to our zip file.

Now to verify it, go to your zip file in the system. Right-click on it and select open with Archive Manager.

It can be seen that the Documents folder is added to the zip file.

How To Delete Files From a Zip
We can also delete our zip files using the command line terminal.
First, let’s see which files are present in our zip file using the command:
$ zip -sf files.zip

Now to delete a specific file, use the below-listed command:
$ zip -d files.zip filename.txt
In our scenario, we have deleted the text file 5 as shown below:

To verify whether the file is deleted or not, use the zip -sf files.zp command again.

It can be seen that the file 5 is deleted successfully.
How To Create and Encrypt Zip File
-e keyword is used to add password encryption to protect your zip file from unauthorized access.
To encrypt a zip file, use the following command:
$ zip -e files *.txt
It can be seen that the system prompts the user to provide a password to see the contents of a zip file.

Conclusion
A commonly used archive file format for files and folders is known as Zip. To zip files in a linux terminal we can use the zip files filenames command. To see the contents of a zip file, use the zip -sf files.zip command. To add a directory to a zip file, we can use the zip -r files directoryname command. To delete a zip file, use the zip -d files.zip filename command. This blog post discussed how to zip a file in a Linux terminal.