We often need to compress a folder or directory to a .zip file. In linux, we can use zip command to implement. In this tutorial, we will use some examples to show you how to do.
Compress some files
We do not need to compress a file. If we want to compress some files to a .zip file, we can use command below:
zip archivename.zip filename1 filename2 filename3
zip test.zip 1.wav 2.wav
We will compress 1.wav and 2.wav to test.zip file.
Compress a folder
It is easy to compress a folder, we can use this command:
zip -r archivename.zip directory_name
zip -r test.zip wavs
We will compress wavs directory to test.zip
If you do not want any output, you can add -q argument.
zip -qr test.zip wavs
Compress some folders
We also can compress some folders using zip command. Here is the example:
zip -r archivename.zip directory_name1 directory_name2
Compress some folders and files
We also can compress some files and folders at the same time.
zip -r archivename.zip directory_name1 directory_name2 file1 file1