首页 > 解决方案 > 如何在 bash 脚本中使用 find 命令检查目录大小

问题描述

我需要找到大于特定值的目录大小,我为此编写了一个脚本。但是 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 `+'

标签: linuxbashshell

解决方案


为了消除 bash 脚本中的错误替换错误。用双倍配额包装可变大小。

    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

echo "+${size}G";

find $path  -type d -size "+${size}G" -exec ls -ld {} \;

推荐阅读