File archiving is used when one or more files need to be transmitted or stored as efficiently as possible.
Archiving: Combines multiple files into one, which eliminates the overhead in individual files and makes the files easier to transmit.
Compression: Makes the files smaller by removing redundant information. Its two types : lossless, lossy
Lossless: No info is removed from the file. Compressing a file and decompressing= identical to the original.
Lossy : Info might be removed from the file. uncompressing a file = slightly different from the original.
When an archive is decompressed, and one or more files are extracted, this is called un-archiving.
1 | zip | Archive=combines files and keeps original files as it is | |
2 | gzip | Compress files along archive(only files) by replacing original files | Lempel-Ziv data compression |
3 | tar | To compress a directory | |
3 | bzip2 | Compress files+archive by replacing files, gen2 of gz(good compr.) | Burrows-Wheeler block sorting |
zip: files+folders – combining – no compress
1 | Zip file/folder | zip <zip file name> <folder/file needs to zip> | zip one.zip /home/user/dir |
2 | Unzip file/folder | Unzip <zip file name> | unzip <zipfile.zip> |
3 | Remove file from zip | Zip -d <zipfile.zip> <files/folders to zip> | zip -d hii.zip hii2 |
4 | Add file zipped file | zip -u <zipfile.zip> <files/folders to zip> | zip -u hii.zip hii2-add |
5 | Delete original after zip | zip -m <zipfile.zip> <files/folders to zip> | Zip -m one.zip /home/user/one/ |
6 | Recursive zip(inner folder) | zip -r <zipfile.zip> <files/folders to zip> | zip -r one.zip /home/user/one |
7 | Exclude file | zip -x <zipfile.zip> <files/folders to exclude> | zip -m one.zip one.txt |
8 | Verbose (info as response) | Zip -v <zipfile.zip> <files/folders to zip> | zip -v one.zip one.txt |
gzip (GNU (GNU’S Not Unix) zip) : files – compression at low size
1 | compress file | gzip | gzip one.zip |
2 | Uncompress files | gunzip <file>
gunzip -d <File> |
gunzip one.zip.gz
gzip -d one.zip.gz |
3 | To see compress ratio | gzip -l <file> | gzip -l onetwo.zip |
bzip2 (bunzip) : compress a file like gzip command but takes a little more time but compresses better.
1 | compress file | bzip2 <files> | bzip all.zip |
2 | Uncompress files | bzip2 -d <files> | bzip -x all.zip.bz2 |
Tar(Tap Archive): combine+compress → files and folder → again you can add .gz and bz2 compression
c : create | v : display output | f : mentioned destination dir. to store | z : compress with gz | j : compress with bzip2 |
1 | compress file/folder | tar -cvf <filename.tar> <files/folders> | tar -cvf all.tar * |
2 | compress file/folder gz | tar -cvfz <filename.tar> <files/folders> | tar -cvfz all.tar * |
3 | compress file/folder bzip2 | tar -cvfj <filename.tar> <files/folders> | tar -cvfj all.tar * |
4 | To list the files in | tar -tvf <filename.tar> | tar -tvf all.tar |
5 | Extract the tar | tar -xvf <filename.tar> | tar -xvf all.tar |