linux-tutorial/codes/linux/tool/查看指定目录磁盘使用情况.sh

20 lines
353 B
Bash

#!/bin/bash
#DIRS="/var/log /home /opt"
#DATE=$(date '+%m%d%y')
#exec > disk_space_${DATE}.log
echo "Top Ten Disk Space Usage"
echo "for ${DIRS} Directories"
for DIR in ${DIRS}
do
echo ""
echo "The ${DIR} Directory:"
du -S ${DIR} 2>/dev/null |
sort -rn |
sed '{11,$D; =}' |
sed 'N; s/\n/ /' |
gawk '{printf $1 ":" "\t" $2 "\t" $3 "\n"}'
done