Não é uma solução usando ferramentas embutidas, mas eu peguei um script python para fazer o que eu quero. Aqui está, se ajudar alguém. Ainda procurando uma solução incorporada, se houver uma.
#!/usr/bin/python3.6
import os
import time
import sys
if len(sys.argv) != 2:
print('''Usage: {} <file>
Fills a file/device with zeros, with efficiencies for sparse files.'''.format(sys.argv[0]))
exit(1)
f = open(sys.argv[1], 'rb+', 0)
bs = 1024*1024 # block size
zb = b'#!/usr/bin/python3.6
import os
import time
import sys
if len(sys.argv) != 2:
print('''Usage: {} <file>
Fills a file/device with zeros, with efficiencies for sparse files.'''.format(sys.argv[0]))
exit(1)
f = open(sys.argv[1], 'rb+', 0)
bs = 1024*1024 # block size
zb = b'%pre%'*bs # a full block of zeros
lasttime = round(time.time())
block = f.read(bs)
while len(block) == bs:
# IFF a block contains non-zero characters, zero it
if block != zb:
f.seek(-bs, os.SEEK_CUR)
f.write(zb)
block = f.read(bs)
# Print the processed bytes every second
# Could add a MB/s or % completed, but too lazy
if round(time.time()) != lasttime:
print(f.tell())
lasttime = round(time.time())
# Hit EOF, might have missed bytes at the end
# Zero last block unconditionally, too lazy to check if its required
f.seek(-bs, os.SEEK_CUR)
f.write(zb)
f.close()
'*bs # a full block of zeros
lasttime = round(time.time())
block = f.read(bs)
while len(block) == bs:
# IFF a block contains non-zero characters, zero it
if block != zb:
f.seek(-bs, os.SEEK_CUR)
f.write(zb)
block = f.read(bs)
# Print the processed bytes every second
# Could add a MB/s or % completed, but too lazy
if round(time.time()) != lasttime:
print(f.tell())
lasttime = round(time.time())
# Hit EOF, might have missed bytes at the end
# Zero last block unconditionally, too lazy to check if its required
f.seek(-bs, os.SEEK_CUR)
f.write(zb)
f.close()