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?
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.
Using '–t' option in tar command we can view the content of tar files without extracting it.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With