In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about the difference between tar,gunzip,gzip,unzip and zgrep commands. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.
1:tar
Tar [- cxtzjvfpPN] files and directories.
Parameters:
-c: create a parameter instruction for a compressed file (meaning create)
-x: unlock a parameter instruction for a compressed file!
-t: check the files in tarfile!
Pay special attention to that only one c/x/t can exist in the issue of parameters! Cannot exist at the same time!
Because it is impossible to compress and decompress at the same time.
-z: does it also have the properties of gzip? That is, is it necessary to use gzip compression?
-j: does it also have the properties of bzip2? That is, is it necessary to use bzip2 compression?
-v: display files in the process of compression! This is commonly used, but is not recommended in the background execution process!
-f: use the file name, please note that the file name should be connected immediately after f! No more parameters!
For example, using "tar-zcvfP tfile sfile" is the wrong way to write it.
"tar-zcvPf tfile sfile" is right!
-p: use the original properties of the original file (the attributes will not change based on the user)
-P: can use absolute path to compress!
-N: it is newer than the following date (yyyy/mm/dd) before it is packaged into the new file!
-- exclude FILE: do not package FILE in the process of compression!
Example:
Example 1: package all the files in the entire / etc directory into / tmp/etc.tar
[root@linux ~] # tar-cvf / tmp/etc.tar / etc
Example 2: what documents are found in the above / tmp/etc.tar.gz file?
[root@linux ~] # tar-ztvf / tmp/etc.tar.gz
# because we use gzip compression, when we want to check the files in the tar file
# you have to add the parameter z! This is very important!
Example 3: extract the / tmp/etc.tar.gz file under / usr/local/src
[root@linux ~] # cd / usr/local/src
[root@linux src] # tar-zxvf / tmp/etc.tar.gz
# under preset circumstances, we can unzip the compressed files everywhere! Take this example.
# I will first change the working directory to / usr/local/src and unlock / tmp/etc.tar.gz
# the unlocked directory will be in / usr/local/src/etc! In addition, if you enter / usr/local/src/etc
# you will find that the file attributes in this directory may be different from / etc/!
Example 4: under / tmp, I just want to unlock the etc/passwd in / tmp/etc.tar.gz.
[root@linux ~] # cd / tmp
[root@linux tmp] # tar-zxvf / tmp/etc.tar.gz etc/passwd
# I can look up the file name in tarfile through tar-ztvf, if only one file is needed
# can be delivered in this way! pay attention to! The root directory in etc.tar.gz / has been removed!
Example 5: back up all the files in / etc/ and save their permissions!
[root@linux ~] # tar-zxvpf / tmp/etc.tar.gz / etc
The attribute of this-p is very important, especially if you want to keep the attribute of the original file!
Example 6: in / home, files that are newer than 2005-06-01 are backed up
[root@linux] # tar-N "2005-06-01"-zcvf home.tar.gz / home
Example 7: I want to back up / home, / etc, but not / home/dmtsai
[root@linux] # tar-- exclude / home/dmtsai-zcvf myfile.tar.gz / home/* / etc
Example 8: package / etc/ and unpack it directly under / tmp without generating files!
[root@linux ~] # cd / tmp
[root@linux tmp] # tar-cvf-/ etc | tar-xvf-
# this action is a bit like cp-r / etc / tmp ~ it still has its uses!
# pay attention to the fact that the output file becomes-and the input file becomes -, and there is another | exist ~
# this stands for standard output, standard input and pipeline commands, respectively!
2:gunzip
Gunzip (gnu unzip)
Function description: decompress the file.
Grammar: gunzip [- acfhlLnNqrtvV] [- s] [file.] Or gunzip [- acfhlLnNqrtvV] [- s] [directory]
Note: gunzip is a widely used decompression program that is used to unzip files compressed by gzip, which default to the final extension ".gz".
In fact, gunzip is the hard connection of gzip, so whether it is compressed or decompressed, it can be done independently through the gzip instruction.
Parameters:
-an or-- ascii uses ASCII text mode.
-c or-- stdout or-- to-stdout outputs the decompressed file to a standard output device.
-f or-force forcibly unzip the compressed file, regardless of whether the file name or hard connection exists and whether the file is a symbolic link.
-h or-- help online help.
-l or-- list lists information about the compressed file.
-L or-- license displays version and copyright information.
When unzipping-n or-- no-name, if the compressed file contains a distant file name and timestamp, it will be ignored and not processed.
When-N or-- name unzips, if the compressed file contains the original file name and timestamp, it will be saved back to the unzipped file.
-Q or-- quiet does not display a warning message.
-r or-- recursive recursive processing, processing all files and subdirectories under the specified directory together.
-S or-- suffix changes the compressed suffix string.
-t or-- test tests whether the compressed file is correct.
-v or-- verbose shows the instruction execution process.
-V or-- version displays version information.
3:gzip
Gzip command
Key words: gzip
Gzip command
Reducing file size has two obvious benefits, one is that it can reduce storage space, and the other is that it can reduce the transfer time when transferring files over the network.
Gzip is a command that is often used in Linux system to compress and decompress files, which is convenient and easy to use.
Syntax: gzip [option] compressed (unzipped) file name
The meaning of each option:
-c writes the output to standard output and keeps the original file.
-d decompress the compressed file.
-l for each compressed file, the following fields are displayed:
The size of the compressed file
The size of the uncompressed file
Compression ratio
The name of the uncompressed file
-r recursively finds the specified directory and compresses or decompresses all files in it.
-t test to check whether the compressed file is complete.
-v displays the file name and compression ratio for each compressed and unzipped file.
-num adjusts the speed of compression with the specified numeric num,-1 or-fast represents the fastest compression method (low compression ratio), and-9 or-- best represents the slowest compression method (high compression ratio).
The system default is 6.
Suppose there are files mm.txt, sort.txt, xx.com in a directory / home.
Example 1: compress each file in the / home directory into a .gz file.
$cd / home
$gzip *
$ls
M.txt.gz sort.txt.gz xx.com.gz
Example 2: decompress each compressed file in example 1 and list detailed information.
$gzip-dv *
Mm.txt.gz 43.1%-replaced with mm.txt
Sort.txt.gz 43.1%-replaced with sort.txt
Xx.com.gz 43.1%-replaced with xx.com
$ls
Mm.txt sort.txt xx.com
Example 3: the information of each compressed file in example 1 is displayed in detail and is not decompressed.
$gzip-l *
Compressed uncompr. Ratio uncompressed_name
277 445 43.1% mm.txt
278 445 43.1% sort.txt
277 445 43.1% xx.com
$ls
Mm.txt.gz sort.txt.gz xx.com.gz
Example 4: compress a tar backup file, such as usr.tar, with a .tar.gz extension
$gzip usr.tar
$ls
Usr.tar.gz
#
4:unzip command
How can the files compressed by winzip under MS Windows system be expanded under Linux system? You can use the unzip command, which is used to unzip a compressed file with a .zip extension.
Syntax: unzip [option] compressed file name. Zip
The meaning of each option is:
The-x file list unzips the file, but does not include the specified file file.
-v View the directory of compressed files, but do not unzip them.
-t test the file for damage, but do not unzip it.
The-d directory unloads the compressed files to the specified directory.
-z displays only comments for compressed files.
-n does not overwrite existing files.
-o overwrite existing files and do not require user confirmation.
-j does not reconstruct the directory structure of the files and unzips all files to the same directory.
Example 1: unzip the compressed file text.zip in the current directory.
$unzip text.zip
Example 2: extract the compressed file text.zip under the specified directory / tmp. If the same file already exists, the unzip command is required not to overwrite the original file.
$unzip-n text.zip-d / tmp
Example 3: view the compressed file directory, but do not extract it.
$unzip-v text.zip
6:zgrep command
The function of this command is to find a matching regular expression in the compressed file, using the same as the grep command, except that the object of the operation is the compressed file.
If the user wants to see if there is a sentence in a compressed file, he can use the zgrep command.
These are the differences between the tar,gunzip,gzip,unzip and zgrep commands shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.