du命令查看使用空间,对文件和目录磁盘使用的空间的查看。
du [选项][文件]
-a或-all 显示目录中个别文件的大小。-b或-bytes 显示目录或文件大小时,以byte为单位。-c或--total 除了显示个别目录或文件的大小外,同时也显示所有目录或文件的总和。-k或--kilobytes 以KB(1024bytes)为单位输出。-m或--megabytes 以MB为单位输出。-s或--summarize 仅显示总计,只列出最后加总的值。-h或--human-readable 以K,M,G为单位,提高信息的可读性。-x或--one--xystem 以一开始处理时的文件系统为准,若遇上其它不同的文件系统目录则略过。-L <符号链接> 或--dereference <符号链接> 显示选项中所指定符号链接的源文件大小。-S或--separate- 显示个别目录的大小时,并不含其子目录的大小。-X <文件> 或--exclude-from= <文件> 在 <文件> 指定目录或文件。--exclude= <目录或文件> 略过指定的目录或文件。-D或--dereference-args 显示指定符号链接的源文件大小。-H或--si 与-h参数相同,但是K,M,G是以1000为换算单位。-l或--count-links 重复计算硬件链接的文件。 目录或文件> 文件> 文件> 文件> 符号链接> 符号链接>
下面介绍du加强版
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"echo "统计目录下各文件及目录的大小"echo "sh $0 参数1(目录)"echo " 参数2 遍历深度(默认0)"echo " 参数3 Y/N 是否显示极小文件"echo "统计目录下各文件及目录的大小"
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
#/bin/bash# by llhlecho "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"echo "统计目录下各文件及目录的大小"echo "sh $0 参数1(目录)"echo " 参数2 遍历深度(默认0)"echo " 参数3 Y/N 是否显示极小文件"echo "统计目录下各文件及目录的大小"echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"level=$2function secho() { times=$1 while [ $times -gt 0 ]; do echo -e " \c" times=$((times - 1)) done}function showBigFile() { result=$( echo $1 | grep "^.*K ") if [[ "$result" != "" ]] then echo -e "\c" else resultSub=$( echo $1 | grep "^0 ") if [[ "$resultSub" != "" ]] then echo -e "\c" else echo $1 fi fi}function grepBigFile() { result=$( echo $1 | grep $2 ) if [[ "$result" != "" ]] then return "" else return $1 fi}function echoSize() { d_f_size=`du -sh $1` if [[ $2 == 'Y' ]] then echo $d_f_size else showBigFile "$d_f_size" fi}function size() { for element in `ls -AXrS $1` do if [ $1 == "/" ] then dir_or_file=$1$element else dir_or_file=$1"/"$element fi if [ -d $dir_or_file -a $2 -gt 0 ] then size $dir_or_file $[$2-1] $3 else secho $[$level-$2] echoSize $dir_or_file $3 fi done}function main() { size $1 $2 $3}main ${1:-'/'} ${2:-0} ${3:-'Y'}echo ""