Sample Header Ad - 728x90

How to display the non-sparse parts of a sparse file?

10 votes
1 answer
528 views
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.
Asked by St&#233;phane Chazelas (579282 rep)
Mar 26, 2014, 03:05 PM
Last activity: Apr 12, 2025, 01:57 PM