Detailed explanation of the compression and decompression commands under Linux and a simple example of the compression and decom

Linux and a simple example

Unzip the zip file to the current directory

unzip filename.zip

linux zip command

1.zip -r myfile.zip ./* All files and folders in the current directory are compressed into myfile.zip file, and -r indicates all files in the recursive compression subdirectory.

2.unzip Unzip -o -d /home/sunny myfile.zip Extract the myfile.zip file to /home/sunny/ -o: Overwrite the file without prompting; -d:-d /home/sunny indicates that the files are extracted to the /home/sunny directory;

3. Others 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 myfile.zip in the compressed file

To compress the file using zip, type the following command at the shell prompt: Zip -r filename.zip filesdir

To extract the contents of the 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 and spacing them with spaces. Zip -r filename.zip file1 file2 file3 /usr/work/school

@ command Detailed

-c: Create compressed file -x: decompress -t: View content -r: append files to the end of the compressed archive -u: Update the files in the original archive These five are independent commands. One of them is used for compression and decompression. It can be used with other commands but only one of them can be used. The following parameters are optional when compressing or decompressing files as needed.

-c: Create a compressed file -x: decompress -t: View content -r: append files to the end of the compressed archive -u: Update the file in the original zip file

The following parameter -f is required -f: Use the file name, remember, this parameter is the last parameter, only the file name can be followed. # tar -cf all.tar *.jpg

This command is to make all .jpg files into a package called all.tar. -c indicates that a new package is generated, and -f specifies the file name of the package. # tar -rf all.tar *.gif

This command adds all .gif files to the all.tar package. -r means to add a file. # tar -uf all.tar logo.gif

This command is to update the original tarball all.tar logo.gif file, -u is the meaning of updating the file. # tar -tf all.tar

This command lists all the files in the all.tar package, and -t is the meaning of the files listed. # tar -xf all.tar

This command is to solve all the files in the all.tar package, -t is the meaning of unlocking

压缩

tar –cvf jpg.tar *.jpg / / All the jpg files in the directory are packaged into tar.jpg Tar –czf jpg.tar.gz *.jpg //Pack all the jpg files in the directory into jpg.tar and compress them with gzip to generate a gzip-compressed package named jpg.tar.gz Tar –cjf jpg.tar.bz2 *.jpg //Pack all the jpg files in the directory into jpg.tar and compress them with bzip2 to generate a bzip2 compressed package named jpg.tar.bz2 Tar –cZf jpg.tar.Z *.jpg //Pack all the jpg files in the directory into jpg.tar and compress them with compress to generate a umcompress compressed package named jpg.tar.Z Rar a jpg.rar *.jpg //rar format compression, you need to download rar for linux first Zip jpg.zip *.jpg //zip format compression, you need to download zip for linux

Tar –xvf file.tar //decompress tar package Tar -xzvf file.tar.gz //Unzip tar.gz Tar -xjvf file.tar.bz2 //Unzip tar.bz2 Tar –xZvf file.tar.Z //Unzip tar.Z Unrar e file.rar / / extract rar Unzip file.zip //Unzip zip

1, *.tar with tar –xvf decompression 2, *.gz decompress with gzip -d or gunzip 3, .tar.gz and .tgz decompress with tar –xzf 4, *.bz2 use bzip2 -d or unzip with bunzip2 5, *.tar.bz2 decompress with tar –xjf 6, *.Z uncompress with uncompress 7, *.tar.Z decompress with tar –xZf 8, *.rar with unrar e decompression 9, *.zip Unzip unzip

Linux tar command detailed (reproduced information)

tar command Tar can create files for files and directories. With tar, users can create files (backup files) for a particular file, change files in a file, or add new files to a file. Tar was originally used to create files on tape, and now users can create files on any device, such as floppy disks. With the tar command, you can package a whole bunch 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. The tar on Linux is the GNU version. Syntax: tar [main option + sub-options] file or directory When using this command, the main option is mandatory. It tells tar what to do. The auxiliary option is auxiliary and can be used.

主选:

c Create a new archive file. If the user wants to back up a directory or some files, choose this option. r Append the file to be archived to the end of the archive. For example, if the user has already made a backup file and finds that there is still a directory or some files forgotten to back up, you can use this option to append the forgotten directory or file to the backup file. t List the contents of the archive and see which files have been backed up. u Update the file. That is to say, the original backup file is replaced with the newly added file, and if the file to be updated is not found in the backup file, it is appended to the end of the backup file. x Release the file from the archive. Auxiliary options: b This option is set for the tape drive. It is followed by a number to indicate the size of the block. The system default is 20 (20*512 bytes). f Use an archive file or device. This option is usually required. k Save the existing file. For example, we restore a file, and during the restore process, we encounter the same file and will not overwrite it. m When restoring files, set the modification time of all files to the current one. M Create a multi-volume archive for storage on several disks. v Detailed report of file information processed by tar. If you do not have this option, tar does not report file information. w Every step requires confirmation. z Use gzip to compress/decompress files. After adding this option, you can compress the archive file, but you must use this option to decompress it when restoring. Anatomy of compressed files under Linux

For those who are new to Linux, it will definitely give Linux a bunch of various file names. Don't say anything, just compress 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. However, 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 There are too few people using .zip and .rar on Linux. This article will summarize some of these common compressed files, I hope that you will not be confused when you encounter these files next time.

Before concluding all kinds of compressed files, we must first understand two concepts: packaging and compression. Packing refers to turning a bunch of files or directories into a total file. Compression is to convert a large file into a small file through some compression algorithm. Why do you want to distinguish between 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 large number of files, you have to use the other tools to A bunch of files are first packaged into a package, and then compressed on the original compression program. The most commonly used packager under

Linux is tar. The package that is used by the tar program is often called a tar package. The commands for tar package files usually end with .tar. After generating the tarball, you can use other programs to compress, so first talk about the basic usage of the tar command:

tar command has many options (can be viewed with man tar), but commonly used Just a few options, here's an example:

# tar -cf all.tar *.jpg This command is to make all .jpg files into a package called all.tar. -c indicates that a new package is generated, and -f specifies the file name of the package.

# tar -rf all.tar *.gif This command adds all .gif files to the all.tar package. -r means to add a file.

# tar -uf all.tar logo.gif This command is to update the logo.gif file in the original tarball all.tar, and -u is the meaning of updating the file.

# tar -tf all.tar This command lists all the files in the all.tar package, and -t is the meaning of the listed files

# tar -xf all.tar This command is to solve all the files in the all.tar package, -t is the meaning of unlocking The above is the most basic usage of tar. In order to facilitate the user to compress or decompress files while packaging and unpacking, tar provides a special feature. This is where tar can call other compression programs at the same time as packaging or unpacking, such as calling gzip, bzip2, and so on.

1) tar calls gzip

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

# tar -czf all.tar.gz *.jpg This command is to convert all .jpg files into a tarball and compress it with gzip to generate a gzip-compressed 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 a stronger compression capability. The file ending with .bz2 is the result of bzip2 compression. The decompression program opposite bzip2 is bunzip2. Use the -j parameter in tar to call gzip. Here's an example:

# tar -cjf all.tar.bz2 *.jpg This command is to convert all .jpg files into a tarball and compress it with bzip2 to generate a bzip2 compressed package named all.tar.bz2

# tar -xjf all.tar .bz2 This command is to unpack the package generated above.

3) tar call compress

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

# tar -cZf all.tar.Z *.jpg This command is to convert all .jpg files into a tarball and compress them with compress to generate an uncompress-compressed package named all.tar.Z

# tar -xZf all.tar .Z This command is to unlock the package generated above

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

1) .tar ending file 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 files ending in .bz2 Bzip2 -d all.bz2 Bunzip2 all.bz2

5) for files ending with tar.bz2 Tar -xjf all.tar.bz2

6) for files ending in .Z Uncompress all.Z

7) for files ending in .tar.Z Tar -xZf all.tar.z

In addition to the common compressed files under .Window and .rar, Linux also has a corresponding method to extract them:

1) for .zip

# zip All.zip *.jpg This command compresses all .jpg files into a zip package

# unzip all.zip This command 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, you can download it from the Internet, but remember, RAR for Linux Not free; then install: # tar -xzpvf rarlinux-3.2.0.tar.gz # cd rar # make This is installed, there are two programs rar and unrar after installation, rar is the compression program, unrar is the decompression program. They have a lot of parameter options, here is a brief introduction, still give examples of its usage:

rar a all *.jpg

This command compresses all .jpg files into a rar package named all.rar, the program will. The rar extension will be automatically appended to the package name. # unrar e all.rar This command is to extract all the files in all.rar