If I understand you correctly, you are looking for something like:
echo "test line" > file;
for i in {1..21}; do echo "test line" >> file; done
That will create a file with 22 repetitions of "test line". If you want a specific file size, you can use something like this (on Linux). 1024 is one kilobyte:
while [ $(stat -c "%s" file) -le 1024 ]; do echo "test line" >> file; done
Personally, when I want to create a large file, I use two files and cat one into the other. You can repeat the process until you reach the desired size (1MB here):
echo "test line" > file;
while [ $(stat -c "%s" file) -le 1048576 ]; do
cat file >> newfile
cat newfile >> file
done
Note that this solution will often exceed the desired size because if the file is under the limit, everything will be catted into it again.
Finally, if all you want is a file of the desired size and don't need it to actually contain anything, you ca use truncate
:
truncate -s 1M file
for i in {1..1000000};do echo "string" >> file;done
in bash.type file >> file
to run in an infinite loop (at least as soon as it's sufficiently large that it doesn't fit in a buffer).