Program for identifying files from unfinished torrent-downloads

bittorrentfilessearch

Are there any programs that can help identify files and directories belonging to unfinished bittorrent-downloads? I've made a mess, and I'm unsure of which downloads are finished and which are not. I could obviously use the bt-client, if I still had the torrent-files, but I don't. I'm therefor looking for way to identify likely unfinished bt-downloads – doesn't have to be 100% accurate.

I've noticed that bt-clients typically create empty-files, as well as leave files with "holes" (blocks of the file with just NULL-characters), so this could perhaps be a good way to find likely candidates. Sadly, I don't know any good Linux-commands for finding files with blocks of NULLs…

Best Answer

If your grep supports it; you could do a check by grep.

grep -P '\x00{NNN}' File

Where NNN is how many continuously zero bytes you want to match. Would typically be max USHRT_MAX or 65535.

-P is needed to use \x00

To list offsets use:

grep -Pboa '\x00{NNN}' File

So something in the direction of:

for f in *; do
    [ -e "$f" ] || break
    if grep -Pq '\x00{1000}' "$f"; then 
        mv "$f" ../likely_corrupt
    fi
done

Else you could use hexdump, xxd or the like and match for 000....

hexdump -ve '/1 "%02X"'

But that would be crazy slow.


Finally a very short C program could do the same.

Related Question