Generating Huge String Buffer in Bash

The below bash script could be used to generate a file of a particular size (here 20MB) with some random strings.

#!/bin/bash
wanted_size=$((1024*1024*20)) #20MB File
function gen_file()
{
	file_size=$(( ((wanted_size/12)+1)*12 ))
	read_size=$((file_size*3/4))
	dd if=/dev/urandom bs=$read_size count=1 | base64 > /tmp/file
	truncate -s "$wanted_size" /tmp/file 
	cat /tmp/file #Will show some random string data , Optional
}
gen_file

Leave a Reply