Upload a File on Ubuntu Using Zip
In this tutorial, I will give you a consummate guide and every important selection listed on "How to Zip a File in Linux". Zipping a file or directory in Linux helps to have backup and save disk infinite by compressing unused files. I am using Ubuntu Linux twenty.04 to showcase all examples in this post.
What is Zip
Zip is basically a file packaging and compression utility for almost every operating system, whether it's any Linux flavour, Windows, Mac and even some RISC systems.
Information technology is always installed on all Linux or Unix system past default except few cases. Information technology is analogous to a combination of two commands tar and compress.
Generally, zip program puts one or more than compress files in Linux into a single cipher archive forth with meta-information near the file.
The pinch ratio of zip files in Linux is around two:ane or three:1 are common of text files and it varies for unlike file types. Unmarried zip command can put an entire directory structure into a zip archive.
In instance of large archives greater than 4GB, naught automatically uses zip64 extension. Nil is uniform with Pkzip and Pkunzip utilities as well.
Zip also at present supports bzip2 compression utility, if the bzip2 library generally gets compiled with zip.
Unzip and tar are two companion utilities. Unzip unpacks or decompress zip archive and tar is used to take backup.
Pre-requisite of Zip utility
There is no special pre-requisite, the only thing y'all demand to exercise is to bank check whether zip is installed in Linux or not.
Run this control. it will install goose egg and unzip utility if it's not in that location. If it's already installed, it will upgrade or practice nada as shown in the output.
$ sudo apt install zero unzip

It shows zilch and unzip utility is already on the newest version. so you are washed with installing zip and unzip till this point and you lot are ready to explore the world of Shrink files and folder in Linux.
If you have Centos or Fedora distro. Run below-mentioned commands to install cipher and unzip
$ sudo yum install zip
$ sudo yum install unzip
I volition explicate zipping files in Linux using two options
- Zip a file in Linux using Graphical user interface (GUI)
- Zip a file in Linux using command line interface (CLI)
Let's check out first option -
How to zip a file in Linux GUI
Step1:-
Go to the directory where file or folders resides.
Step2:-
Select files and correct-click - select compress.
Step3:-
Give annal name. I will give sample-zip as an case.

Step4:-
You lot are washed !!

How to zip a file in Linux terminal
Outset, have a look at Syntax of zip with explanation -
$ null options "output_file_name" "target_file" "target_folder"
Where
output_file_name - the name of the output file yous want to requite. nothing extension will automatically add together.
target_file or folder - is file or binder path which you want to cypher and it may take wildcards.
Allow'due south see unlike options and examples of Zip programme one by one.
Example 1:- How to shrink or zip files in Linux
dev@test:~$ nada test file1 file2
output
adding: file1 (deflated 69%)
adding: file2 (deflated 69%)
dev@test:~$ ls exam*
test.null
dev@examination:~$
File name and compression % is reflected in the output. As you tin can see I take not included .goose egg extension, notwithstanding by default command add together that into output-file name. In my instance "exam-zip.zip".
if you want to suppress this output of zilch control, yous tin use -q option.
dev@exam:~$ zip -q test file1 file2
Output
dev@test:~$ ls -ltrh examination*
-rw-r--r-- one dev dev 56K Jun 18 16:xxx test.zip
dev@test:~$
There may be the example, if you forgot to give output-file-name in aught command, so it will by-default pick the beginning file name as the output file and second file into zip. So beneath mentioned example likewise show, how to nothing multiple files in Linux.
dev@examination:~$ cipher file1 file2
Output
calculation: file2 (deflated 69%)
dev@exam:~$ ls -fifty *.zip
-rw-r--r-- one dev dev 28519 Jun eighteen 16:33 file1.zip
Case 2:- How to zip binder and subfolders in Linux
Mostly, you need to create cypher archive to the directory containing files and subdirectories. Zip option -r will be useful to traverse that directory construction recursively.
dev@test:~$ zip -r examination sample/
Output
calculation: sample/ (stored 0%)
calculation: sample/file2 (deflated 69%)
adding: sample/file1 (deflated 69%)
dev@test:~$ ls sample*
test.zip
Compression levels in Zip utility
The default compression level of the zip file is -6 and yous have all the liberty to choose a number between 0-9. if yous select -0 and so there will be no compression, means no compress files in Unix.
if you will select -9 volition forcefulness zip program to select best optimal pinch for all files or folders.
Example three:- How to utilise pinch level 0 & 9
dev@test:~$ naught -r -0 exam.naught sample/
Output
adding: sample/ (stored 0%)
adding: sample/file2 (stored 0%)
adding: sample/file1 (stored 0%)
output shows, if I select 0 as compression level, there is no compression at all during zipping of the files or folder.
For instance -
dev@test:~$ zip -r -nine test sample/
Output
adding: sample/ (stored 0%)
calculation: sample/file2 (deflated 69%)
adding: sample/file1 (deflated 69%)
dev@exam:~$
if Zip found that file tin't be compressed, it just archives and stores it equally-is without shrink file in Linux.
I have talked nigh bzip2 besides in my zip introduction statement. bzip2 is also installed by default in all Linux version. If you want to compress the file using bzip2 method, -Z can be used.
Instance 4:- How to zilch a file in Linux using bzip2 utility
dev@exam:~$ cipher -r -Z bzip2 test.goose egg sample/
Output
calculation: sample/ (stored 0%)
calculation: sample/file2 (bzipped 74%)
adding: sample/file1 (bzipped 74%)
dev@test:~$ ls test.zilch
exam.zip
If you will compare the output, compression ratio increased for the same files from 69% to 74% using with bzip2.
So bzipping files may result in more space-saving merely changing compression level or using bzip2 to get more space-saving comes with penality of CPU resource and information technology will take more time to shrink in case of a large number of files in Linux.
But it will definitely save network resources if you are planning to transfer or send information technology over the internet.
Zip and encrypt a file in Linux
Many times you demand to store or need to send/transfer a file to someone and information technology may incorporate sensitive or personal information.
To avert misuse of this file, you can ever encrypt or enable password on archive file using -e pick.
Example five:- How to enable password on the zip file in Linux
dev@test:~$ zip -e test.zip sample/
Output asking for countersign
Enter password:
Verify password:
adding: sample/ (stored 0%)
dev@test:~$ ls sample
sample/ test.zip
Don't forget to share the password with the recipient, if y'all are going to send information technology to someone 🙂
Create a split zip file in Linux
There may exist a case when you have a big file to archive and yous need to split it due to storage or upload limits on FTP site or file hosting vendor.
Y'all can create a cipher file using -s option with providing size. The multiplier can be set as grand(kilobytes), k(Megabytes), t(Terabytes).
Instance half dozen:- How to create a dissever zip file in Linux
I have a zip file of Ubuntu xx.04 iso image with name ubuntu.zip (two.5G) and I will divide information technology into 1g archive files.
dev@examination:~/sample$ ls -ltrh ubuntu.zip -rw-r--r-- one dev dev ii.5G Jun eighteen 17:51 ubuntu.zip
dev@test:~/sample$ cipher -south 1g ubuntu.zip --out dissever copying: ubuntu-20.04-desktop-amd64.iso dev@exam:~/sample$
Output
dev@examination:~/sample$ ls -ltrh split*
-rw-r--r-- 1 dev dev ane.0G Jun 18 eighteen:03 split.z02
-rw-r--r-- ane dev dev 504M Jun 18 18:04 split.zip
-rw-r--r-- one dev dev 1.0G Jun xviii 18:04 divide.z01
Accept a look on dissever.nada, separate.z01 and split.z02
Now when you have split the file using zip and you will exist thinking of joining this on target. Don't worry, I won't allow you scratch your caput.
Case 7:- How to add or combine a split zip file in Linux
Become to the directory where y'all take kept split files
dev@examination:~/sample$ ls -ltrh dissever*
Output
-rw-r--r-- 1 dev dev 1.0G Jun 18 18:03 split.z02
-rw-r--r-- 1 dev dev 504M Jun eighteen 18:04 carve up.zip
-rw-r--r-- one dev dev i.0G Jun 18 xviii:04 split.z01
now Join split zip files.
dev@test:~/sample$ cat split.z* > join.nil
Validate the size in output
dev@examination:~/sample$ ls -ltrh join.zip
-rw-r--r-- 1 dev dev 2.5G Jun 18 18:thirteen join.null
Example viii:- How to update a zip file in Linux
let'due south assume you forgot to add one file into a zip or desire to add more than files to existing zip, then -u option can help. In this example, I will add file4 to existing test.zip file.
dev@exam:~$ zip -u test.zilch file4
Output
adding: file4 (deflated 69%)
Example 9:- How to exclude a file from a zip annal in Linux
A scenario where you have a lot of files in a directory and you want to exclude some files from being zip archived. Selection -10 is the saviour here.
Currently, I have three files in the sample directory
dev@exam:~$ ls -ltrh sample/
full 264K
-rw-r--r-- i dev dev 88K Jun 17 21:51 file1
-rw-r--r-- 1 dev dev 88K Jun 17 23:21 file2
-rw-r--r-- 1 dev dev 88K Jun 18 18:20 file3
let's exclude file3, only two files archived.
dev@exam:~/sample$ zip test.zip * -x file3
Output
adding: file1 (deflated 69%)
adding: file2 (deflated 69%)
dev@test:~/sample$
Example 10:- Verbose mode in zipping files in Linux
if you lot want to encounter the progress, -5 option known as verbose or diagnostic version info tin can be helpful specially when you are working with a large number of files.
dev@test:~$ zip -5 -r exam.naught sample/
Output
adding: sample/ (in=0) (out=0) (stored 0%)
adding: sample/file3 (in=90082) (out=28359) (deflated 69%)
adding: sample/file2 (in=90082) (out=28359) (deflated 69%)
calculation: sample/file1 (in=90082) (out=28359) (deflated 69%)
total bytes=270246, compressed=85077 -> 69% savings
dev@test:~$
Example 11:- Working with wildcards to compress files in Linux
The by and large used wildcard is an asterisk(*) in this earth, in my view, Aught utility supports this helpful wildcard graphic symbol. No need to type each and every file proper noun.
dev@exam:~/sample$ nada file.cipher file*
Output
adding: file1 (deflated 69%)
adding: file2 (deflated 69%)
adding: file3 (deflated 69%)
dev@exam:~/sample$
Some common issues and fault codes during zipping in Linux
Condition output
0 normal; no errors or warnings detected, means archiving washed
2 unexpected end of zip file in Unix.
11 read or seek mistake, Unable to read the file
12 zip has nix to do, Some activity is missing
13 missing or empty cypher file
14 error writing to a file
Video tutorial
To brand information technology easier on "how to zip a file in Linux" for beginners, I have created a video also. Delight scout, similar and share, if you establish it useful.
Conclusion
We learnt all-important functionality of null utility in this tutorial and promise provided examples are good enough to understand it.
if yous still face whatever event or want to explore more on zipping files in Linux or shrink files in Unix, use "man zip" control or man page in Linux. Probably the best source of information.
Further reading recommendations:-
Ubuntu installation on Virtual machine and Install Chrome on Linux
Afterward this "How to zip a file in Linux" tutorial, Soon I volition render with "unzip" post. Till that time, relish...
Please exit your comments or feedback. information technology will motivate to write more than helpful posts.
Source: https://cloudlinuxtech.com/zip-a-file-in-linux/
0 Response to "Upload a File on Ubuntu Using Zip"
Post a Comment