Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2007
    Posts
    6

    Unanswered: tar and gzip question

    Hello again!

    I have a file filename.tar.gz. I would like to see a list of the files in the tarball as well as the number of lines in each file.

    I know wc -l will give me the number of lines in a file.
    I know that tar -t will give me a list of the files in a tarball.
    I know that gzcat will show me the contents of a compressed file without uncompressing it.

    My first attempt was
    Code:
    gzcat filename.tar.gz | tar -t | wc -l
    but that isn't right....

    What I'm having problems with is putting these commands together to produce the desired result. Are these even the best commands to use? Is there a better (easier) way?

    Any help would be appreciated.

    Thanks,
    Brian

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    you need -f with tar
    gzcat filename.tar.gz | tar -tf - | wc -l
    or with gnu tar
    tar -tzf filename.tar.gz | wc -l

  3. #3
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    This will give you a count of files because it operates on the output of "tar -tzf".

    If you want to have the line count of each file, you will have to untar the archive and then scan on the files.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  4. #4
    Join Date
    Sep 2007
    Posts
    6
    Thanks for the quick responses guys.

    Maybe a list of the files will be sufficient for what my user is requesting. I'm not sure if he will want to untar the archive or not, but I'll present him with the facts you've given and let him decide how to proceed.

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •