0

I have a tar.gz file (neatly 1TB size). I want to count the number of files inside this tar.gz file. I used the following command

tar -tzf file.tar.gz

but it only lists the file name while I need the exact number of files. Any help would be much appreciated.

0

1 Answer 1

1

You can pipe the output of tar to the wc command and tell it to count the lines using the -l parameter:

tar -tzf file.tar.gz | wc -l

Example:

I created a tgz archive with a single file inside then I counted how many files the said archive contained:

$ tar -czf anaconda.tgz Anaconda3-2019.10-Windows-x86_64.exe
$ tar -tzf anaconda.tgz | wc -l
1
2
  • 1
    Thanks Higor, it also worked for me!
    – Taufiq
    Nov 18, 2020 at 20:06
  • Please mark the question as solved/answered.
    – Higor E.
    Mar 26, 2021 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.