编写一个shell脚本,任意传入一个目录,找出该目录下最大的文件?

如题所述

#!/bin/bash
function usage()
{
echo "USAGE: disk_usage.sh [-a -n N] directory..."
exit
}
function show()
{
dir=$1
if [[ $showall == "true" ]];then
ls -l --color=auto $dir
else
ls -l --color=auto $dir | grep -v total | head -n $shown
fi
}
showall=false
shown=10
while getopts 'an:' opt; do
case $opt in
a)
showall=true
;;
n)
shown=$OPTARG
;;
?)
usage
;;
esac
done
shift $(($OPTIND - 1))
if [[ -z $1 ]] || [[ ! -d $1 ]];then
usage
fi
show $1
温馨提示:内容为网友见解,仅供参考
第1个回答  2019-12-15
人工智能为主,科学技术维普。
相似回答