2

I can use /dev/zero or /dev/urandom to write values into a file. Is there also a way to write an unlimited amount (just restricted by a command line switch maybe) of defined numbers (e.g. 1, 2, etc.) into a file?

I know about echo "1" > file but I need moooore!

The file should contain the same string value repeated without newlines. Ideally I could write bit test patterns like 0xAA or 0x55, but I guess I can manage that myself once I know how to write one value.

3 Answers3

4

For an unlimited amount of arbitrary data, don't forget about yes!

$ yes 42
42
42
42
42
42
42
42
42
42
42
42
42
^C

Hit Control-C when you've had enough!

Alternatively to Control-C, use timeout:

timeout 10 yes 42
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
1

While loop

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_02.html

plus basic math

 $ a=1
 $ a=$(($a+1))
 $ echo $a
2
matzeri
  • 961
1

Combining

I found the following works best for my needs:

for i in $(busybox seq 10); do echo -n "1" >> filename; done

where 10 defines the number of items to write.