Skip to main content
added 715 characters in body; added 1 character in body
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242

Here are some more dd examples anyway:

dd bs=5000 seek=1 if=/dev/null of=./H.txt

...which creates (or truncates) a \0NUL filled file in the current directory named H.txt of size 5000 bytes. dd seeks straight to the offset and NUL-fills all behind it.

<&1 dd bs=5000 conv=sync,noerror count=1 | tr \\0 H >./H.txt

...which creates a file of same name and size but filled w/ H chars. It takes advantage of dd's spec'd behavior of writing out at least one full null-block in case of a read error when noerror and sync conversions are specified (and - without count= - would likely go on longer than you could want), and intentionally redirects a writeonly file descriptor at dd's stdin.

Here are some more dd examples anyway:

dd bs=5000 seek=1 if=/dev/null of=./H.txt

...which creates (or truncates) a \0NUL filled file in the current directory named H.txt of size 5000 bytes. dd seeks straight to the offset and NUL-fills all behind it.

<&1 dd bs=5000 conv=sync,noerror count=1 | tr \\0 H >./H.txt

...which creates a file of same name and size but filled w/ H chars. It takes advantage of dd's spec'd behavior of writing out at least one full null-block in case of a read error when noerror and sync conversions are specified (and - without count= - would likely go on longer than you could want), and intentionally redirects a writeonly file descriptor at dd's stdin.

deleted 2 characters in body
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242
timestime bash -c 'printf H%.0s {1..5000}' >/dev/null
timestime bash -c 'printf %05000s|tr \  H' >/dev/null
times bash -c 'printf H%.0s {1..5000}' >/dev/null
times bash -c 'printf %05000s|tr \  H' >/dev/null
time bash -c 'printf H%.0s {1..5000}' >/dev/null
time bash -c 'printf %05000s|tr \  H' >/dev/null
added 504 characters in body; added 1 character in body; added 23 characters in body
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242
iterator=$start
until [ "$((start+=intervaliterator+=interval))" -gt "$end" ]; do ...

Anyway, like the space padding mentioned before, you can also use printf to padzeropad an arbitrary number of digits, of course, like:

You can get as many 0's like:

I do both without arguments because for every argument specified in printf's format string when an argument is not found the null string is used - which is interpreted as a zero for a digit argument or an empty string for a string.

This is the other (and - in my opinion - more efficient) side of the coin when compared with the command in the question - while it is possible to get nothing from something as you do when you printf %.0 length strings for each argument, so also is it possible to get something from nothing.

until [ "$((start+=interval))" -gt "$end" ]; do ...

Anyway, like the space padding mentioned before, you can also use printf to pad an arbitrary number of digits, of course, like:

You can get as many 0's like:

iterator=$start
until [ "$((iterator+=interval))" -gt "$end" ]; do ...

Anyway, like the space padding mentioned before, you can also use printf to zeropad an arbitrary number of digits, of course, like:

I do both without arguments because for every argument specified in printf's format string when an argument is not found the null string is used - which is interpreted as a zero for a digit argument or an empty string for a string.

This is the other (and - in my opinion - more efficient) side of the coin when compared with the command in the question - while it is possible to get nothing from something as you do when you printf %.0 length strings for each argument, so also is it possible to get something from nothing.

added 1277 characters in body
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242
Loading
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242
Loading