Reputation: 1032
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?
Upvotes: 30
Views: 52831
Reputation: 741
you can use the tar -vv verbose option twice for full verbose, then grep the first character from file permissions. the ^ means only match first character (begin of line). the grep -c option count the lines.
drwxrwx--x directory
lrwxrwxrwx symlink
-rw-rw---- file
count regular files only
gzip -cd file.tar.gz | tar -tvv | grep -c ^-
Upvotes: 8
Reputation: 1032
I found the solution!
I used unpigz for those files and it changed the file extensions to .tar . after that I could use tar -tzf without any problems.
Thanks!
Upvotes: 0
Reputation: 2393
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
Upvotes: 43