I have a directory tree that in each directory there is a file called zero-file
I want this file to be initialized with specific number of zero's for example 10000000000.
I want to write ASCII character '0'
I found 2 solutions for this
for i in `seq 1 10000000000`
do
echo -n 0 >> zero-file
done
The second one is this: I initialized a file called base and the copy this file in each directory
cp base zero-file
This was faster. I want to know if there exist a faster way.
Try using /dev/zero as a virtual input file that contains only zeros. You can copy a fixed number of bytes with dd:
dd if=/dev/zero of=zero-file bs=1 count=10000000000
This copies one byte 10000000000 times from /dev/zero to zero-file. You can adjust the blocksize and count as needed.
To write zeros to zero-file:
dd if=/dev/zero bs=1 count=10000000000 | tr '\0' '0' > zero-file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With