Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count the number of files inside a tar.gz file (without decompressing)?

I have a tar.gz file which I have made by pigz (parallel gzip). I wanted to count the number of files inside the compressed file without decompressing it.

I use this command:

tar -tzf file.tar.gz

but I got an error:

tar: This does not look like a tar archive
tar: Skipping to next header

Is it because I used pigz instead of gzip? If yes how can I count the them now?

like image 702
user3576287 Avatar asked May 11 '14 14:05

user3576287


People also ask

How do I count files in tar gz?

Since it is a tar and gzip archive you should use z option to use gzip. Then simply you can count lines with wc . This answer gave the same file count as gzip -cd file.

Which of the following command is used to see the content of tar file without extracting it?

Using '–t' option in tar command we can view the content of tar files without extracting it.

How do I count the number of lines in a gz file in Unix?

The command gzgrep behaves the same as grep but on gzip compressed files. It decompress the file on the fly for the regex matching. In this case -c instruct the command to output number of matched lines and the regex $ matches end of line so it matches every line or the file.


1 Answers

Since it is a tar and gzip archive you should use z option to use gzip. Then simply you can count lines with wc.

tar -tzf file.tar.gz | wc -l
like image 183
jdiver Avatar answered Oct 02 '22 02:10

jdiver