Is it possible to get the size that a tgz will take up once it's extracted, but without extracting it? I basically want

tar tzf file.tgz
with sizes beside them. I'm really looking for a total, so a solution that gives total size but not specific file sizes would work.

4 Answers 4


If it compressed using gzip compression, you can do something like:

gunzip -l filename.tar.gz

Since a tar is not compressed, that should give you the information you need.

  • Hm, to easy ;) +1
    – Node
    May 19, 2009 at 16:03

Hm I would prefer something like:

tar vtzf somefile.tar.gz |awk '{SUM += $3} END {print SUM}'
  • This is the closest to correct. Ideally you would round each $3 up to the filesystem block size. Variations in filesystems make this very difficult to solve in general. At least awk '{SUM+=($3>512?$3:512)}END{print SUM}' - but if you know the filesystem blocksize (if there is one), replace 512 with the actual blocksize.
    – carlito
    May 24, 2009 at 0:18
zcat file.tgz | wc -c

Will give you the number of characters taken up by the uncompressed .tar file, which will be very close to correct.


I'm finding everything sites in the web, and don't resolve this problem the get size when file size is bigger of 4GB.

first, which is most faster?

[oracle@base tmp]$ time zcat oracle.20180303.030001.dmp.tar.gz | wc -c

    real    0m45.761s
    user    0m43.203s
    sys     0m5.185s
[oracle@base tmp]$ time gzip -dc oracle.20180303.030001.dmp.tar.gz | wc -c

    real    0m45.335s
    user    0m42.781s
    sys     0m5.153s
[oracle@base tmp]$ time tar -tvf oracle.20180303.030001.dmp.tar.gz
    -rw-r--r-- oracle/oinstall 111828 2018-03-03 03:05 oracle.20180303.030001.log
    -rw-r----- oracle/oinstall 6666911744 2018-03-03 03:05 oracle.20180303.030001.dmp

    real    0m46.669s
    user    0m44.347s
    sys     0m4.981s

definitely, tar -xvf is the most faster, but ¿how to cancel executions after get header?

my solution is this:

[oracle@base tmp]$  time echo $(timeout --signal=SIGINT 1s tar -tvf oracle.20180303.030001.dmp.tar.gz | awk '{print $3}') | grep -o '[[:digit:]]*' | awk '{ sum += $1 } END { print sum }'

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.