在 Bash 中检查文件夹大小 [英] Check folder size in Bash
问题描述
我正在尝试编写一个脚本来计算目录大小,如果大小小于 10GB,大于 2GB 则执行一些操作.我需要在哪里提及我的文件夹名称?
I'm trying to write a script that will calculate a directory size and if the size is less than 10GB, and greater then 2GB do some action. Where do I need to mention my folder name?
# 10GB
SIZE="1074747474"
# check the current size
CHECK="`du /data/sflow_log/`"
if [ "$CHECK" -gt "$SIZE" ]; then
echo "DONE"
fi
推荐答案
您可以:
du -hs your_directory
这将为您提供目标目录大小的简要输出.使用像 *
这样的通配符可以选择多个目录.
which will give you a brief output of the size of your target directory. Using a wildcard like *
can select multiple directories.
如果您想要目标内所有文件和子目录的完整大小列表,您可以执行以下操作:
If you want a full listing of sizes for all files and sub-directories inside your target, you can do:
du -h your_directory
提示:
添加参数
-c
以在末尾看到 Total 行.示例:du -hcs
或du -hc
.
Add the argument
-c
to see a Total line at the end. Example:du -hcs
ordu -hc
.
删除参数 -h
以查看精确 KiB 中的大小,而不是人类可读的 MiB 或 GiB 格式.示例:du -s
或 du -cs
.
Remove the argument -h
to see the sizes in exact KiB instead of human-readable MiB or GiB formats. Example: du -s
or du -cs
.
这篇关于在 Bash 中检查文件夹大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!