写一个shell脚本执行时第一个参数为空时目标目录是当前目录第一个参数不为空时目标目录是参数值然后遍历目标目录所有文件利用dd命令将随机二进制数填充进所有文件文件大小保持不变
#!/bin/bash if [ -z "$1" ]; then target_dir="./" else target_dir="$1" fi
for file in "$target_dir"/*; do if [ -f "$file" ]; then filesize=$(stat -c%s "$file") dd if=/dev/urandom of="$file" bs=1 count="$filesize" conv=notrunc echo "Filled $file with random binary data." fi done
echo "Finished filling all files in $target_dir with random binary data."
原文地址: https://www.cveoy.top/t/topic/dhWb 著作权归作者所有。请勿转载和采集!