Hi
I need to write a script to run search for the longest filename excluding the file extension through subdirectories given the argument as a dir i.e. "./script dir".
the problems with the script:
1. it did not work for searching through subdirectories even for "ls -R"
2. cannot check files with the white spaces e.g. "my file.txt".
3. And also, how do i include the absolute path o the file that is found with the longest length e.g.
the longest filenamed is "\usr\bin\longestfilename".
many thanks, Daryl
this is my humble script:
#1/bin/bash
maxfile="."
for file in $(ls -a1R $1)
do
file1=${file%.*}
file1_len=${#file1}
if test $file1_len -gt ${#maxfile}
then
maxfile=$file1
fi
done
echo "The maximum length of the file is ${#maxfile}, Filename: "$maxfile""
echo "$(ls -R $pwd | grep $maxfile)"
for file in $(ls -a1R $1)
do
file1=${file%.*}
file1_len=${#file1}
if test $file1_len -eq ${#maxfile}
then
if test $file1 != $maxfile
then
echo "The maximum length of the file is ALSO ${#file1}, Filename: "$file""
echo "$(ls -R $pwd | grep $file)"
fi
fi
done