Check the total content size of a tar gz file

后端 未结 7 1224
醉话见心
醉话见心 2020-12-23 19:00

How can I extract the size of the total uncompressed file data in a .tar.gz file from command line?

相关标签:
7条回答
  • 2020-12-23 19:27

    Use the following command:

    tar -xzf archive.tar.gz --to-stdout|wc -c
    
    0 讨论(0)
  • 2020-12-23 19:34

    The command gzip -l archive.tar.gz doesn't work correctly with file sizes greater than 2Gb. I would recommend zcat archive.tar.gz | wc --bytes instead for really large files.

    0 讨论(0)
  • 2020-12-23 19:35

    This will sum the total content size of the extracted files:

    $ tar tzvf archive.tar.gz | sed 's/ \+/ /g' | cut -f3 -d' ' | sed '2,$s/^/+ /' | paste -sd' ' | bc
    

    The output is given in bytes.

    Explanation: tar tzvf lists the files in the archive in verbose format like ls -l. sed and cut isolate the file size field. The second sed puts a + in front of every size except the first and paste concatenates them, giving a sum expression that is then evaluated by bc.

    Note that this doesn't include metadata, so the disk space taken up by the files when you extract them is going to be larger - potentially many times larger if you have a lot of very small files.

    0 讨论(0)
  • 2020-12-23 19:39

    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
    
        real    0m1.005s
        user    0m0.013s
        sys     0m0.066s
    
    
    0 讨论(0)
  • 2020-12-23 19:44

    If you want to do this from the command-line, you could try the -l option to gzip:

    $ gzip -l compressed.tar.gz
         compressed        uncompressed  ratio uncompressed_name
                132               10240  99.1% compressed.tar
    
    0 讨论(0)
  • 2020-12-23 19:44

    I know this is an old answer; but I wrote a tool just for this two years ago. It’s called gzsize and it gives you the uncompressed size of a gzip'ed file without actually decompressing the whole file on disk:

    $ gzsize <your file>
    
    0 讨论(0)
提交回复
热议问题