The yes command (Section 14.5) outputs text over and over.[121] If you need a file of some size for testing, make it with yes and head (Section 12.12). For example, to make a file 100k (102,400) characters long, with 12,800 8-character lines (7 digits and a newline), type:
[121]Believe it or not, it does have a purpose; it was originally designed to pipe "y" answers into interactive programs such as fsck before those programs provided the option to proceed with implicit approval. The FreeBSD 4.4 manual says of yes(1) that it "outputs expletive, or, by default, 'y'", forever.
% yes 1234567 | head -12800 > 100k-file
NOTE: On some Unix systems, the command may "hang" and need to be killed with CTRL-c because head keeps reading input from the pipe. If it hangs on your system, replace head -12800 with sed 12800q.
You might just want to use perl, instead:
$ perl -e 'print "1234567\n" x 12800' > file
For the Unix admin who has everything, here's one more way, this time using the venerated dd command:
$ yes | dd of=file count=25
There are many variations on this theme. The preceding example simply copies 25 blocks of 512 bytes each from standard input (the output of the yes command) to the file file. You could also specify a number of bytes to read at a time, using the ibs option, and then specify the number of records to write out, using count:
$ yes | dd ibs=1 of=file count=12800
There's More Than One Way To Do It. Be careful, though -- you can fill up a disk pretty quickly playing around with the dd command!
Copyright © 2003 O'Reilly & Associates. All rights reserved.