4

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.
Steve Armstrong
  • 155
  • 2
  • 6

4 Answers4

13

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.

WerkkreW
  • 5,969
  • 3
  • 24
  • 32
1

Hm I would prefer something like:

tar vtzf somefile.tar.gz |awk '{SUM += $3} END {print SUM}'
Node
  • 1,644
  • 1
  • 13
  • 15
  • 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 '09 at 00:18
0
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.

MikeyB
  • 39,291
  • 10
  • 105
  • 189
-1

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
    6667028480

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

    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 }'
    6667023572