Linux under the puzzled Package view tar package file content __linux

Source: Internet
Author: User
Tags gz file

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.