尝试这个
#!/bin/bash
filler="$1" #save the filename
path="$filler"
#find an existing path component
while [ ! -e "$path" ]
do
path=$(dirname "$path")
done
#stop if the file points to any symlink (e.g. don't fill your main HDD)
if [ -L "$path" ]
then
echo "Your output file ($path) is an symlink - exiting..."
exit 1
fi
# use "portable" (df -P) - to get all informations about the device
read s512 used avail capa mounted <<< $(df -P "$path" | awk '{if(NR==2){ print $2, $3, $4, $5, $6}}')
#fill the all available space
dd if=/dev/urandom of="$filler" bs=512 count=$avail 2>/dev/null
case "$?" in
0) echo "The storage mounted to $mounted is full now" ;;
*) echo "dd errror" ;;
esac
ls -l "$filler"
df -P "$mounted"
将代码保存到文件,例如:ddd.sh
并像这样使用它:
bash ddd.sh /path/to/the/filler/filename
代码是在https://stackoverflow.com/users/171318/hek2mgl的帮助下完成的