Code:
#!/bin/bash
#Revision Number 1.1
#Pass directory as first argument ($1)
#Initialization
maxlen=0
#Check for directory argument
if [ $# -ne 1 ]; then
echo "Usage: len.sh [directory]"
exit
fi
#Obtain list of filenames for directory and store it in namelist
ls -lpR $1 | grep -v / | tr -s " " | cut -d" " -f9 > namelist
#Find longest name
for file in `cat namelist`; do
len=${#file}
if [ $len -gt $maxlen ]; then
((maxlen=len))
maxfilename=$file
fi
done
#Display it
echo "Longest filename in $1 is $maxfilename with length=$maxlen"
#Remove temporary file
rm -f namelist
2004-06-19
display the longest filename, given a directory as argument
订阅:
博文评论 (Atom)
没有评论:
发表评论