Probably easiest to use tr
to convert the zeroes from /dev/zero
to whatever you want, and then cut to length using dd
or head
or such.
This would write 18520 bytes with all bits ones, so value 0xff or 255, or 377 in octal as the input must be:
< /dev/zero tr '\000' '\377' | head -c 18520 > test.bin
(To convert from hex or decimal to octal, you could use printf "%o\n" 0xff
or such. )
To produce streams of longer than one-byte strings, I'd use Perl:
perl -e '$a = "abcde" x 1024; print $a while 1' | head ...
(Of course you could use "\xff"
or "\377"
there, too. I used the repetition operator x 1024
there mostly to avoid minimally small writes. Changing it may or may not affect the performance of that.)