tar pre-run to evaluate expected size or amount of files

yanger picture yanger · Apr 24, 2013 · Viewed 14.3k times · Source

The problem: I have a back-end process that at some point he collect and build a big tar file. This tar receive few directories and an exclude files. the process can take up to few minutes and i want to report in my front-end process (GUI) about the progress of the taring process (This is a big issue for a user that press download button and it seems like nothing is happening...).

i know i can use -v -R in the tar command and count files and size progress but i am looking for some kind of tar pre-run mode / dry run to help me evaluate either the expected number of files or the expected tar size.

the command I am using: tar -jcf 'FILE.tgz' 'exclude_files' 'include_dirs_and_files'

10x for everyone who is willing to assist.

Answer

doub1ejack picture doub1ejack · Dec 9, 2013

You can pipe the output to the wc tool instead of actually making a file.

With file listing (verbose):

[git@server]$ tar czvf - ./test-dir | wc -c
./test-dir/
./test-dir/test.pdf
./test-dir/test2.pdf
2734080

Without:

[git@server]$ tar czf - ./test-dir | wc -c
2734080