I have a directory with over 400 GiB of data in it. I wanted to check that all the files can be read without errors, so a simple way I thought of was to tar
it into /dev/null
. But instead I see the following behavior:
$ time tar cf /dev/null .
real 0m4.387s
user 0m3.462s
sys 0m0.185s
$ time tar cf - . > /dev/null
real 0m3.130s
user 0m3.091s
sys 0m0.035s
$ time tar cf - . | cat > /dev/null
^C
real 10m32.985s
user 0m1.942s
sys 0m33.764s
The third command above was forcibly stopped by Ctrl+C after having run for quite long already. Moreover, while the first two commands were working, activity indicator of the storage device containing .
was nearly always idle. With the third command the indicator is constantly lit up, meaning extreme busyness.
So it seems that, when tar
is able to find out that its output file is /dev/null
, i.e. when /dev/null
is directly opened to have the file handle which tar
writes to, file body appears skipped. (Adding v
option to tar
does print all the files in the directory being tar
'red.)
So I wonder, why is this so? Is it some kind of optimization? If yes, then why would tar
even want to do such a dubious optimization for such a special case?
I'm using GNU tar 1.26 with glibc 2.27 on Linux 4.14.105 amd64.
find . -type f -exec shasum -a256 -b '{}' +
. Not only does it actually read and checksum all the data, but if you store the output, you can re-run it later to check that the content of the files hasn't changed.pv
:tar -cf - | pv >/dev/null
. That sidesteps the issue and gives you a progress information (the variouspv
options)gtar -cf /dev/zero ...
to get what you like.