Estimate size of .tar.gz file before compressing

gzip

Solution

Yes, there is a way to estimate tar size before running the command.

tar -czf - /directory/to/archive/ | wc -c 

Meaning: This will create the archive as standar output and will pipe it to the wc command, a tool that will count the bytes. The output will be the number of bytes in the archive. Technically, it runs the tool but doesn't save it.

Source: The Ultimate Tar Command Tutorial with 10 Practical Examples

Problem

We are working on a system (on Linux) that has very limited transmission resources. The maximum file size that can be sent as one file is defined, and we would like to send the minimum number of files. Because of this, all files sent are packed and compressed in GZip format (.tar.gz). There are a lot of small files of different type (binary, text, images...) that should be packed in the most efficient way to send the maximum amount of data everytime. The problem is: is there a way to estimate the size of the tar.gz file without running the tar utility? (So the best combination of files can be calculated)

Original source