#!/bin/bash
#--------------------------------------
#本脚本获取文件夹下最大的前n个文件
#日期:2016/7/24
#作者:齐豪
#--------------------------------------
Usage(){
echo "usage: ./3.myip.sh [-n N] [-d DIR]"
echo "Show top N largest files/directories"
exit
}
printPwd(){
echo "The largest files/directories in $(pwd) are:"
ls -sh | sort -rn | awk '{ print "\t" NR "\t" $1 "\t" $2}'
exit
}
printIntent(){
local path=$2
local n=$1
n="1,"$n"p"
echo "The largest files/directories in $2 are:"
ls -sh $path | sort -rn | sed -n $n | awk '{ print "\t" NR "\t" $1 "\t" $2}'
exit
}
if [ -z $1 ]; then
printPwd;
elif [[ $1 = "-n" && $3 = "-d" ]]; then
printIntent $2 $4;
else
Usage;
fi
获取文件夹下最大的前n个文件
最新推荐文章于 2021-05-08 15:07:39 发布