Linux system - decompression command collection


The linux zip command



zip -r myfile.zip ./*

compresses all files and folders in the current directory into myfile.zip files, -r means recursively compresses all files in subdirectories.



2.unzip

unzip -o -d / home/sunny myfile.zip

Unzip the myfile.zip file to /home/sunny/

-o: Overwrite the file without prompting;

-d:-d /home/sunny specifies to unzip the file to the /home/sunny directory ;



3. Other

zip -d myfile.zip smart.txt

delete the smart.txt file in the compressed file

zip -m myfile.zip ./rpm_info.txt

Add the rpm_info.txt file to the myfile.zip in the compressed file

----- -------------------------------------------------- ------------------------



Linux Operations

- To use

zip
to compress files, type the following command at a shell prompt:



zip -r filename.zip filesdir





In this example, filename.zip is the file you created, and filesdir is the directory where you want to place the new zip file. The -r option specifies that you want to recursively include all files included in the filesdir directory.



To extract the contents of a zip file, type the following command:



unzip filename.zip





You can use the zip command to process multiple files and directories at the same time by listing them one by one separated by spaces:



zip -r filename.zip file1 file2 file3/ The command above usr





/work/school compresses the contents of file1, file2, file3, and the /usr/work/school directory (assuming this directory exists) into the filename.zip file.







tar command details



-c: create a compressed archive



-x: decompress



-t: view the content



-r: append a file to the end of the compressed archive



-u: update the files in the original compressed package



  These five are independent commands, both compression and decompression are required. Using one of them can be used in conjunction with other commands but only one of them can be used. The following parameters are optional when compressing or decompressing archives as needed.



-c: create a compressed archive



-x: decompress



-t: view the content



-r: append a file to the end of the compressed archive



-u: update the files in the original compressed package The



  following parameters -f are required



-f: use the file name, Remember, this parameter is the last parameter and can only be followed by the file name.



# tar -cf all.tar *.jpg



  This command is to type all .jpg files into a package named all.tar. -c means to generate a new package, -f specifies the file name of the package.



# tar -rf all.tar *.gif



  This command is to add all .gif files to the all.tar package. -r means to add files.



# tar -uf all.tar logo.gif



  This command is to update the logo.gif file in the original tar package all.tar, -u means to update the file.



# tar -tf all.tar



  This command is to list all the files in the all.tar package, -t means to list the files



# tar -xf all.tar



  This command is to extract all the files in the all.tar package, -t means



  unzip Compress



tar –cvf jpg.tar *.jpg //Pack all jpg files in the directory into tar.jpg



tar –czf jpg.tar.gz *.jpg //Pack all jpg files in the directory After it becomes jpg.tar, and compress it with gzip to generate a gzip compressed package named jpg.tar.gz



tar –cjf jpg.tar.bz2 *.jpg //Pack all jpg files in the directory into jpg .tar, and compress it with bzip2 to generate a bzip2 compressed package named jpg.tar.bz2



tar –cZf jpg.tar.Z *.jpg //Pack all jpg files in the directory into jpg.tar, and compress it with compress to generate a umcompress compressed package named jpg.tar.Z



rar a jpg.rar *.jpg //For compression in rar format, you need to download rar forlinux



zip first jpg.zip *.jpg //For compression in zip format, you need to download zip forlinux first to



  decompress



tar –xvf file.tar //Decompress the tar package



tar -xzvf file.tar.gz //decompress tar.gz



tar -xjvf file.tar.bz2 //decompress tar.bz2



tar –xZvf file.tar.Z //decompress tar.Z



unrar e file.rar //decompress rar



unzip file.zip //



  Summary of decompression zip



1, *.tar decompress with tar -xvf



2, *.gz decompress with gzip -d or gunzip



3, *.tar.gz and *.tgz decompress with tar -xzf



4, * .bz2 is decompressed with bzip2 -d or bunzip25, *.tar.bz2 is decompressed with tar



-xjf6 , *.Z is decompressed



with uncompress7



, *.tar.Z is decompressed with tar -xZf8



, *.rar is decompressed with unrar e decompress



9, *.zip Unzip



Linux tar command in detail (reproduced information)



2008-04-17 Thursday 15:37 The



tar command



tar can create archives for files and directories. Using tar, users can create archives (backup files) for a particular file, change files in an archive, or add new files to an archive. Originally used to create archives on tape, tar can now be created on any device, such as a floppy disk. Using the tar command, you can package a large number of files and directories into one file, which is very useful for backing up files or combining several files into one file for network transmission. tar on Linux is the GNU version.



  Syntax: tar [main option + auxiliary option] file or directory



  When using this command, the main option is necessary, it tells tar what to do, and the auxiliary option is auxiliary and can be used.



  Main options:



c Create a new archive. If the user wants to backup a directory or some files, select this option.



r Appends the file to be archived to the end of the archive. For example, if the user has already made backup files, and finds that there is another directory or some files that he forgot to back up, this option can be used to append the forgotten directory or file to the backup file.



t List the contents of archive files to see which files have been backed up.



u Update files. That is to say, replace the original backup file with the newly added file. If the file to be updated cannot be found in the backup file, it will be appended to the end of the backup file.



x Release the file from the archive.



  Secondary options:



b This option is set for tape drives. Followed by a number, used to describe the size of the block, the system default value is 20 (20*512 bytes).



f To use an archive or device, this option is usually required.



k Save an existing file. For example, when we restore a certain file, during the restoration process, if the same file is encountered, it will not be overwritten.



m When restoring files, set the modification time of all files to now.



M Creates multi-volume archives for storage on several disks.



v Detailed reporting of file information processed by tar. Without this option, tar does not report file information.



w Every step requires confirmation.



z Use gzip to compress/decompress files, add this option to compress archive files, but be sure to use this option to decompress when restoring.



Analysis of compressed files under Linux



  For those who are new to Linux, they will definitely confuse a lot of various file names under Linux. Not to mention, just take compressed files as an example, we know that there are only two most common compressed files under Windows, one is .zip, and the other is .rap. But Linux is different. It has many compressed file names such as .gz, .tar.gz, tgz, bz2, .Z, .tar, etc. In addition, .zip and .rar under windows can also be used under Linux, but in Very few people use .zip and .rar for Linux. This article will summarize these common compressed files. I hope you will not be confused when you encounter these files next time.



  Before summarizing all kinds of compressed files in detail, we must first clarify two concepts: packaging and compression. Packing refers to converting a large number of files or directories into a total file, while compression refers to converting a large file into a small file through some compression algorithms. Why distinguish these two concepts? In fact, this is because many compression programs in Linux can only compress one file, so when you want to compress a lot of files, you have to use another tool to compress this file first. A large number of files are first packaged into a package, and then compressed with the original compression program.



The most commonly used package program under Linux is tar. The package produced by the tar program is often called a tar package. The commands of a tar package file usually end with .tar. After the tar package is generated, other programs can be used to compress it, so first of all, let's talk about the basic usage of the



tar command: There are many options of the tar command (you can view it with man tar), but only a few are commonly used. Options, let's illustrate with an example:



# tar -cf all.tar *.jpg



  This command is to type all .jpg files into a package named all.tar. -c means to generate a new package, -f specifies the file name of the package.



# tar -rf all.tar *.gif



  This command is to add all .gif files to the all.tar package. -r means to add files.



# tar -uf all.tar logo.gif



  This command is to update the logo.gif file in the original tar package all.tar, -u means to update the file.



# tar -tf all.tar



  This command is to list all the files in the all.tar package, -t means to list the files



# tar -xf all.tar



  This command is to extract all the files in the all.tar package, -t means to unpack The



  above is the most basic usage of tar. In order to facilitate users to compress or decompress files while packing and unpacking, tar provides a special function. This is that tar can call other compression programs, such as calling gzip, bzip2, etc., while packing or unpacking.



1) tar calls gzip



Gzip is a compression program developed by the GNU organization, and files ending in .gz are the result of gzip compression. The decompression program opposite to gzip is gunzip. Use the -z parameter in tar to invoke gzip. Here's an example:



# tar -czf all.tar.gz *.jpg



  This command is to make all .jpg files into a tar package, and compress it with gzip to generate a gzip compressed package, package Named all.tar.gz



# tar -xzf all.tar.gz



  This command is to unpack the package generated above.



2) tar calls bzip2



bzip2 is a compression program with stronger compression ability, and the file ending in .bz2 is the result of bzip2 compression. The decompressor as opposed to bzip2 is bunzip2. Use the -j parameter in tar to invoke gzip. Let's illustrate with an example:



# tar -cjf all.tar.bz2 *.jpg



  This command is to make all .jpg files into a tar package, and compress it with bzip2 to generate a bzip2 compressed package, package Named all.tar.bz2



# tar -xjf all.tar.bz2



  This command is to unpack the package generated above.



3) tar calls compress



compress is also a compression program, but it seems that the people who use compress are not as many as gzip and bzip2. A file ending in .Z is the result of bzip2 compression. The decompression program opposite to compress is uncompress. Use the -Z parameter in tar to invoke gzip. Here's an example:



# tar -cZf all.tar.Z *.jpg



  This command is to make all .jpg files into a tar package, and compress it with compress to generate an uncompress compressed package, the package name is all.tar.Z



# tar -xZf all.tar.Z



  this The command is to unpack the package generated above.



  With above knowledge, you should be able to unpack a variety of compressed files. The following is a summary of the compressed files of the tar series:



1) For files ending in .tar,



tar -xf all. tar



2) for files ending in .gz



gzip -d all.gz



gunzip all.gz



3) for files ending in .tgz or .tar.gz



tar -xzf all.tar.gz



tar -xzf all.tgz



4) for . bz2 ending files



bzip2 -d all.bz2 bunzip2



all.bz2



5) for tar.bz2 ending files



tar -xjf all.tar.bz2



6) for .Z ending files



uncompress all.Z



7) for .tar.Z The file ending with



tar -xZf all.tar.z



  In addition, for common compressed files .zip and .rar under Windows, Linux also has corresponding methods to decompress them:



1) For .zip



zip and unzip programs are provided under linux, zip is a compression program, and unzip is a decompression program. They have a lot of parameter options, which are only briefly introduced here, and still give an example of their usage:



# zip all.zip *.jpg



  This command is to compress all .jpg files into a zip package



# unzip all.zip



  This command It is to extract all the files in all.zip



2) For .rar



  to process .rar files under linux, you need to install RAR for Linux, which can be downloaded from the Internet, but remember that RAR for Linux



  is not free; then install :



# tar -xzpvf rarlinux-3.2.0.tar.gz



# cd rar



# make



  The installation is complete. After installation, there are two programs, rar and unrar. Rar is a compression program, and unrar is a decompression program. They have a lot of parameter options, here is just a brief introduction, and still give an example of their usage:



# rar a all *.jpg



  This command is to compress all .jpg files into a rar package named all.rar, the program will automatically append the .rar extension to the package name.



# unrar e all.rar



  This command is to extract all the files in



  all.rar , we have introduced the linux system

tar, gzip, gunzip, bzip2, bunzip2, compress, uncompress, zip, unzip, rar, unrar and other programs under the 10 kinds of compressed files such as .tar.bz2, .Z, .tar.Z, .zip, and .rar have been decompressed. In the future, there should be no need to worry about downloading a software without knowing how to decompress it under Linux. And the above method is also basically effective for Unix.


Guess you like

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