Traverse through directories

Hi all,

Require help in completing a shell script.

i do have a total of 90 directories where in we have different sub-directories and one of the sub directory named logs

I need to go inside the logs subdirectory and check if a particular log is present or not.

for example below is the folder structure

cd
 /a/b/c/d ;
/a/b/e/f.

I need to traverse through the directories to check the log.

Thanks in advance..

/Bhaskar

Did you consider the find command?

Hello bhaskar t,

Please go through from forum rules, following link may help you in same. We should use code tags for codes and commands which we are using in our posts.
Rules link is as follows.

Let us take a example here let's say we have directory sturcture like /tmp/a/b/c/d where we have files named chuma.test and logs.test .
So to search them from /tmp directory we can use as follows.

find -maxdepth 5 -type f -name "*.test"

Output will be as follows.

./a/b/c/d/logs.test
./a/b/c/d/chuma.test

Hope this helps, also go through from man find page it will be helpful for you.

Thanks,
R. Singh

# going in the tmp directory
cd /tmp
# creating sample directory tree
mkdir -p bhaskar/a/b/c/d/logs \
    bhaskar/b/a/b/c \
    bhaskar/c/a/b/logs \
    bhaskar/d/a/b \
    bhaskar/e/a \
    "bhaskar/f/a b/logs"
# creating three sample log files
touch bhaskar/a/b/c/d/logs/this.log \
    bhaskar/c/a/b/logs/that.log \
    "bhaskar/f/a b/logs/thisthat.log"

With GNU find (searching for this.log file in any of the "logs" directories):

find bhaskar -type f -wholename '*/logs/this.log'

If you don't have GNU find, try this:

find bhaskar -type d -name logs |\
while read logdir; do
  find "$logdir" -type f -name 'this.log'
done