Sunday 10 August 2014

Write a shell script that takes a valid directory name as an argument and recursively descend all the subdirectories, finds the maximum length of any file in that hierarchy and writes this maximum value to the standard output.


if [ $# -ne 1 ]
then
echo "No argument"
exit
fi
if [ ! -e $1 ]
then
echo "The given directory does not exist"
exit
fi
echo "The file with maximum length $1 dir is"
ls -lR $1|tr -s " "|cut -d " " -f 5,10|sort -n|tail -n 1

0 comments:

Post a Comment

 
- |