【发布时间】:2020-12-15 13:00:29
【问题描述】:
我需要找到大于特定值的目录大小,我为此编写了一个脚本。但是 find 命令不接受 -size 部分。谁能帮我解决这个问题
echo -e "This script will generate report for directories which consumes more size than the given value"
read -p " Enter the file system or directory full path: " path
read -p " This script will check the directories which is greater than the given size Please Enter the directory size in GB: " size
find $path -type d -size +$sizeG -exec ls -ld {} \;
错误
find: invalid -size type `+'
【问题讨论】:
-
你的命令寻找一个名为
sizeG的变量;你想要${size}G,或"$size"G,或"${size}G"。 -
目录上的
-size可能无法按预期工作。它不计算目录中文件的大小。您可能需要改用du $path并过滤掉您想要的目录。 -
根据@TedLyngmo 的评论,我以“不重复”的形式重新打开,因为修复变量名错误不会产生您想要的结果。
-
这能回答你的问题吗? Check folder size in Bash
-
如果您想要整个卷的大小,请使用
df而不是du。