Hi People
I am currently on shell script in which I am trying to traverse a directory tree. All the sub directories and files in this directory uses timestamp as their file/directory names.
Requirement :- Need to run cat command on all the files in current directory in order of its timestamp i.e filename that has latest timestamp as filename is to cat first.......,and so on ....after doing cat to all the files I need to check the sub directories , and need to do cd into the sub -directory that has latest time stamp among the directories as a dirname....after doing cd need to perform same processign as defined above ....like this need to traverse all the directories present in the main directory .....
I am a newbie .....I have tried it ...code looks like :
process(){
cd $1
if [ $? -ne 0 ]
then
return 0 # Don't have execute permission, return
fi
local count=0
find . -name "*" -type f -maxdepth 1 -mindepth 1 -exec basename {} \; | sort -nr > ~/tempfiles
while read fname
do
cat $fname > /dev/null
done < ~/tempfiles
find . -name "*" -type d -maxdepth 1 -mindepth 1 -exec basename {} \; | sort -nr > ~/tempdir
while read dirname
do
local array[$count]=${1}/${dirname}
count=$(($count + 1))
done < ~/tempdir
if [ $count -eq 0 ]
then
return 0
fi
local count_T=0
while [ $count_T -lt $count ]
do
process ${array[$count_T]}
count_T=$(($count_T + 1))
done
return 0
}
if [ ! -d "$1" ]
then
echo -e "Please Enter Directory\n"
echo -e "EXITING ....."
exit 0
fi
process $1
I need suggestions from you people ...please advise so that i can learn and make can my script more efficient....any alternate solutions are most welcome....this script is recursive in nature ...is there any iterative solution to the problem becoz this script is consuming lot of time for large directories......