How do I get a file size(original file size) within .tar.gz without uncompress it?

I make myfile.txt to zip file with below command, is there a way to get original file size 'myfile.txt' without unzipping it.

tar -czf myfile.tar.gz myfile.txt

3 Answers

To get the uncompressed size of a ZIP file we can issue gzip with option --list or -l

gzip -l mytext.txt.tar.gz

This will give an output similar to this

gzip -l mytext.txt.tar.gz compressed uncompressed ratio uncompressed_name 1475 4608 68.4% mytext.txt.tar

To have the compressed file size, the uncompressed size, and the compression ratio.

You can list the content (including original file sizes) of the tar file using:

tar -vtf myfile.tar.gz

If you only want myfile.txt:

tar -vtf myfile.tar.gz myfile.txt

This only works if you add the full file path, otherwise use:

tar -vtf myfile.tar.gz | grep myfile.txt

Note that tar will have to decompress the archive in order to get to the file information. It will however hide that from you.

If you specifically need a way to get to file meta-data without having to decompress the whole archive, you are better off using zip to store your files and directories. Zip uses a 'central directory' at the end of a zip-file that stores all file meta-data.

6

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.029s
user 0m0.012s
sys 0m0.063s
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like