生成 size 大小,默认内容为 0xFF 的文件
shell
脚本将如下脚本保存为 generate_blank_bin.sh
#!/bin/bash
if [ $# -lt 1 ]; then
echo -e "\033[31mError Parameter counts:$#, exit\033[0m"
exit
elif [ $# -eq 2 ]; then
tmp=`echo "obase=8;ibase=16;$2" | bc`
character=`echo "\\\\$tmp"`
else
character='\377'
fi
filename=`echo blank_$1.bin`
block_size=4096
block_counts=`expr $1 / $block_size`
remaining_size=`expr $1 % $block_size`
tr '\000' $character < /dev/zero | dd of=$filename bs=$block_size count=$block_counts
if [ $remaining_size -gt 0 ]; then
tr '\000' $character < /dev/zero | dd of=$filename bs=$remaining_size count=1 oflag=append conv=notrunc
fi
./generate_blank_bin.sh size
./generate_blank_bin.sh size hex
size
: 自然数, 例如: 1
, 1024
, 4096000
hex
: 十六进制数, 例如: 11
, AB
, FF
1): 生成 4KB
大小的 blank bin
./generate_blank_bin.sh 4096
将会在当前目录生成一个 blank_4096.bin
, 其大小为 4KB
, 内容为 0xFF
2): 生成 100 字节,内容为 0xCC 的文件
./generate_blank_bin.sh 100 CC
将会在当前目录生成一个 blank_100.bin
, 其大小为 100
字节, 内容为 0xCC