Imagine a file created with:
truncate -s1T file
echo test >> file
truncate -s2T file
I now have a 2 tebibyte file (that occupies 4kiB on disk), with "test\n" written in the middle.
How would I recover that "test" efficiently, that is without having to read the whole file.
tr -d '\0' < file
Would give me the result but that would take hours.
What I'd like is something that outputs only the non-sparse parts of the file (so above only "test\n" or more likely, the 4kiB block allocated on disk that stores that data).
There are APIs to find out which part of the file are allocated (FIBMAP, FIEMAP, SEEK_HOLE, SEEK_DATA...), but what tools expose those?
A portable solution (at least to the OSes that support those APIs) would be appreciated.
strings?trsince it still reads the whole file and does more than just removing the NUL bytes.