Ubuntu handles compressed packages

ZIP

zip is probably the most used document compression format today. Its biggest advantage is that it can be used on different operating system platforms, such as Linux, Windows and Mac OS. The downside is that the supported compression ratios are not very high, while tar.gz and tar.gz2 do very well in terms of compression ratios. Without further ado, let's get down to business:

We can compress a directory with the following command:

# zip -r archive_name.zip directory_to_compress

Here's how to unzip a zip archive:

# unzip archive_name.zip

TAR

Tar is a very widely used document packaging format in Linux. Its advantage is that it only consumes very little CPU and time to package files. It is just a packaging tool and is not responsible for compression. Here's how to package a directory:

# tar -cvf archive_name.tar directory_to_compress

How to unpack:

# tar -xvf archive_name.tar.gz

The above unpack command will unpack the document in the current directory. Of course, you can also pinch the unpacked path with this command:

# tar -xvf archive_name.tar -C /tmp/extract_here/

TAR.GZ

This format is the compression format I use the most. It does not take up too much CPU when compressing, and can get a very ideal compression ratio. Use the following format to compress a directory:

# tar -zcvf archive_name.tar.gz directory_to_compress

unzip:

# tar -zxvf archive_name.tar.gz

The above unpack command will unpack the document in the current directory. Of course, you can also pinch the unpacked path with this command:

# tar -zxvf archive_name.tar.gz -C /tmp/extract_here/

TAR.BZ2

This compression format has the best compression ratio of all the methods we mentioned. Of course, this also means that it takes up more CPU and time than the previous method. This is how you can compress with tar.bz2.

# tar -jcvf archive_name.tar.bz2 directory_to_compress

The above unpack command will unpack the document in the current directory. Of course, you can also pinch the unpacked path with this command:

# tar -jxvf archive_name.tar.bz2 -C /tmp/extract_here/

Data compression is very useful, especially for backups. So, you should now consider backing up your basic rules file in your backup script using the compression method you learned here to reduce the size of your backup file.

After a while, you will realize that there will be a balance between compression ratio and CPU usage time, and you will also learn how to balance when you need a fast but low compression ratio, and when you need a high compression ratio but CPU points with high compression, then you can avoid unnecessary space and time.

If tar does not support the j parameter, use it first

bzip2 -d xxx.tar.bz2

Extract it into a .tar file, then use

tar xvf xxx.tar

Unpack.

Compression and decompression

How to decipher files with suffix gzip under linux?

1. Files with .a extension:

#tar xv file.a

2. Files with .z extension:

#uncompress file.Z

3. Files with .gz extension:

#gunzip file.gz

4. Files with .bz2 extension:

#bunzip2 file.bz2

5. Files with .tar.Z extension:

#tar xvZf file.tar.Z 

或 #compress -dc file.tar.Z | tar xvf -

6. Files with extension .tar.gz/.tgz:

#tar xvzf file.tar.gz 

或 gzip -dc file.tar.gz | tar xvf -

7. Files with .tar.bz2 extension:

#tar xvIf file.tar.bz2 

或 bzip2 -dc file.tar.bz2 | xvf -

8. Files with extension .cpio.gz/.cgz:

#gzip -dc file.cgz | cpio -div

9. Files with .cpio/cpio extension:

#cpio -div file.cpio 

或cpio -divc file.cpio

10. Install a file with a .rpm extension:

#rpm -i file.rpm

11. Unzip the file with the extension .rpm:

#rpm2cpio file.rpm | cpio -div

12. Install a file with a .deb extension:

#dpkg -i file.deb

13. Unzip the file with the extension .deb:

# dpkg-deb --fsys-tarfile file.deb | tar xvf - ar p 

file.deb data.tar.gz | tar xvzf -

14. Files with .zip extension:

#unzip file.zip

Unzip files in Winzip format under linux

  If jdk is installed, you can use the jar command; you can also use the unzip command.

Unzip the .tar.gz file directly

  The xxxx.tar.gz file uses tar with the zxvf parameter, which can be decompressed at one time. XXXX is the file name. E.g:

$tar zxvf xxxx.tar.gz Decompression of various compressed files (installation method)

File extension decompression (installation method)

.a ar xv file.a

.Z uncompress file.Z

.gz gunzip file.gz

.bz2 bunzip2 file.bz2

.tar.Z tar xvZf file.tar.Z

compress -dc file.tar.Z | tar xvf -

.tar.gz / .tgz tar xvzf file.tar.gz

gzip -dc file.tar.gz | tar xvf -

.tar.bz2 tar xvIf file.tar.bz2

bzip2 -dc file.tar.bz2 | xvf -

.cpio.gz/.cgz gzip -dc file.cgz | cpio -div

.cpio/cpio cpio -div file.cpio

cpio -divc file.cpio

.rpm/install rpm -i file.rpm

.rpm/extract rpm2cpio file.rpm | cpio -div

.deb/install dpkg -i file.deb

.deb / exrtact dpkg-deb --fsys-tarfile file.deb | tar xvf -

ar p file.deb data.tar.gz | tar xvzf -

.zip unzip file.zip 

bzip2 -d myfile.tar.bz2 | tar xvf

tar xvfz myfile.tar.bz2

x is decompression

v is the complex output

f is the specified file

z gz format

gzip

gzip [options] filename to compress (or decompress)

-c Write output to standard output and keep the original file.

-d Compresses compressed files.

-l For each compressed file, display the following fields: compressed file size, uncompressed file size, compression ratio, uncompressed file name

-r Recursively finds the specified directory and compresses or compresses all files in it.

-t Test that the compressed file is positive and complete.

-v For each compressed and decompressed file, display its filename and compression ratio.

-num - Adjust the speed of compression with the specified number.

Example:

Make a backup of all files in the /usr directory and its subdirectories, the backup file name is usr.tar

tar cvf usr.tar /home

Make a backup and compress all files in the /usr directory and its subdirectories, the backup file name is usr.tar.gz

tar czvf usr.tar.gz /usr

Compress a set of files, the file suffix is ​​tar.gz

#tar cvf back.tar /back/

#gzip -q back.tar

or

#tar cvfz back.tar.gz /back/

Release a file with the suffix tar.gz.

#tar zxvf back.tar.gz

#gzip back.tar.gz

#tar xvf back.tar

How to use tar:

1: Compress a group of files as tar.gz suffix

tar cvf backup.tar / etc

or gzip -q backup.tar.gz

2: Release a file with a suffix of tar.gz

gunzip backup.tar.gz

或tar xvf backup.tar

3: Compression is done with one command

tar cvf -/etc | gzip -qc >; backup.tar.gz

4: Release with one command

gunzip -c backup.tar.gz | tar xvf -

5: How to unpack the ta.Z file

tar xvfz backup.tar.Z

或uncompress backup.tar.Z

tar xvf backup.tar

6: How to unpack the .tgz file

gunzip backup.tgz

7: How to compress and decompress the .bz2 package

bzip2 /etc/smb.conf This will compress the file smb.conf into smb.conf.bz2

bunzip2 /etc/smb.conf.bz2 restores smb.conf.bz2 to smb.conf in the current directory

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326065167&siteId=291194637