Solutions with dd or head are not straight enough.
The work should be done in the script. Using it should be a no-brainer.
I ended up with this:
Code: Select all
Frandfile ()
{
[[ ! $1 || $1 =~ "-h" || ! $1 =~ ^[0-9]+[kmgKMG]?$ ]] &&
echo "
$FUNCNAME size [file{fr-(size)}] # create file with size randoms
# k 1000 K 1024 m 1000000 M 1048576 g 1000000000 G 1073741824
" && return
# the inevitable separator
local CHR='.'
local SEP='perl -pe'\''while(/\d{5,}/){$b=$`;$m=$&;$a=$'\'"\'"\'';
$m=~s/(?<=\d)(?=(\d{3})+\b)/'$CHR'/;$_="$b$m$a"}'\'
local SIZE=$1
local FILE=${2-fr-$SIZE}
SIZE=`echo $SIZE |sed 's/k/000/;
s/m/000000/;
s/g/000000000/'`
SIZE=`echo $SIZE |perl -pe 's/(\d+)K/$1 * 1024/e;
s/(\d+)M/$1 * 1048576/e;
s/(\d+)G/$1 * 1073741824/e'`
echo -n "create $FILE with `echo $SIZE |eval "$SEP"` bytes ... "
local TIME=`date +%s`
head --bytes $SIZE /dev/urandom >$FILE || return
TIME=$((`date +%s` - $TIME))
printf "%d second%s\n\n" $TIME `(($TIME == 1)) || echo "s"`
case $FILE in
*/*) ls -l $FILE
;;
fr-*) ls -ltr fr-*
;;
*) ls -l $FILE
;;
esac
echo
}
lower is even, upper is power and a default file name.
That's it. Plain and simple.
originaly I used
Code: Select all
openssl rand -out $FILE $SIZE
Example:
Code: Select all
$ Frandfile 100M
create fr-100M with 104.857.600 bytes ... 2 seconds
-rw-r--r-- 1 lxc lxc 1,263,616 03.10. 2023 21:06:53 fr-1234K
-rw-r--r-- 1 lxc lxc 1,234,000 03.10. 2023 21:07:03 fr-1234k
-rw-r--r-- 1 lxc lxc 1,234,567 03.10. 2023 21:07:09 fr-1234567
-rw-r--r-- 1 lxc lxc 1,234,567,000 03.10. 2023 21:07:38 fr-1234567k
-rw-r--r-- 1 lxc lxc 104,857,600 03.10. 2023 21:25:22 fr-100M