You want a special file in Linux, /dev/random serves as a random number generator on a Linux system. /dev/random will eventually block unless your system has a lot of activity, /dev/urandom in non-blocking. We don't want blocking when we're creating our files so we use /dev/urandom.
try this command:
dd if=/dev/urandom bs=1024 count=1000000 of=file_1GB conv=notrunc
This will create a file with bs*count random bytes, in our case 1024*1000000 = 1GB.
The file will not contain anything readable, but there will be some newlines in it.
xKon@xK0n-ubuntu-vm:~/tmp$ dd if=/dev/urandom of=file.txt bs=1048576 count=100 conv=notrunc
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 13.4593 s, 7.8 MB/s
xKon@xK0n-ubuntu-vm:~/tmp$ wc -l file.txt
You can use the option seek with dd to speed up the process a little more:
$ dd if=/dev/zero of=1g.img bs=1 count=0 seek=1G
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 8.12307 s, 132 MB/s
$ ls -lh t
-rw-rw-r-- 1 xK0n xK0n 1.1G 2014-08-05 11:43 t
The disadvantages here are the fact that the file does not contain anything readable and the fact that it is quite a bit slower than the /dev/zero method (around 10 seconds for 100Mb).
You may also like fallocate command that Preallocates space to a file.
fallocate -l 1G test.img
-rw-r--r--. 1 xK0n xK0n 1.0G Aug 05 11:43 test.img