To reduce the amount of space occupied by log files, in many cases we package the log files in days or weeks as tar.gz packages. While this is a good space to take advantage of, it is inconvenient when we want to look at the contents of a compressed package. If it's just a tar.gz file, unzip it, and then use grep, awk, or VI tools to view or process it. However, if there are one months or a year of log need to find some key words of the line, one of the decompression, and then look, is not very realistic. There is no easy way, can not understand the pressure to get what we want.
The answer is yes, it can be implemented using the Zutils Toolkit. Zutils is a set of Toolset for processing compressed files, supported by: gzip, bzip2, Lzip, and XZ. The commands available in the current version are: Zcat, zcmp, Zdiff, and Zgrep.
Direct viewing of the contents of the tar.gz compressed package can be used:
Zcat xxx.tar.gz
But you want to add piping grep directly to the surface. As follows:
[Root@back tmp]# zgrep ' footbar.js ' vsftpd.tar.gz
Binary file (standard input) matches
[Root@back tmp]# Zcat Pd.tar.gz|grep ' footbar.js '
Binary file (standard input) matches
Find out whether the use of Zgrep or use zcat after grep will be an error. I can't. Of course not. View the help documentation for the next zgrep or grep. There are such a line:
--binary-files=text
Add the parameter.
Zcat vsftpd.tar.gz|grep--binary-files=text ' footbar.js ' or
zgrep--binary-files=text ' footbar.js ' vsftpd.tar.gz
Discovery can view the contents of the file! Why, then?
Because I'm compressing it with the tar czvf parameters of the package. Its implementation is compressed by tar and gzip two layers. Lead to its direct inability to pipe. If you do not want to see the package directly to check the compressed package contains those files. You can use the following command:
[Root@back tmp]# tar tvf vsftpd.tar.gz
-rw-------root/root 441453365 2013-06-03 16:19:56-Vsftpd.log
Original address: http://www.361way.com/zcat-tar-zgrep/2550.html
grep Command Reference: Http://man.linuxde.net/grep