Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Dear All,
I want a script that go through all sub directories in a given directory and then go through all the files in a given subdirectory and then I will work out what I want on the files. I have 365 directories in each of the subdirectory comprise 8 files. I want to read each file and run a program on each of the files.
I have been so far able to run a script in one directory as:
for i in *.grd ;
do
bala bala
done
I beleive I need two "For" loops one that reads directory and the other one files. Thank your in advance.
Yacob

I think I answered the question my self. If any want interested in the script, this looks simple and it is:#!/bin/bash
for b in *;
do ( cd $b;
for a in *;
do
echo $a ;done );
doneThis script goes through each directory and looks for each file. Now my question remain, is it possible that to determine the number of directory that I want to read. For instanc e I want to read only directories that are created in one month of the year: from directiry 1-30. Or from 31-61.
Yacob

I found the answer to my last question. To read just part of the directory I used the following so that I control how many directory I read before I start the do loop on the file.
str=`ls /home/2002 | head -30`for file in /home/2002/$str ;
do ( cd $file;
for a in *;
do
echo $a ;done );
done
The script goes only over the first 30 directories and then go over each files. I have still a problem. How can I read only selected directories, like in the first month not all 30 directories but only 28 of them but not necessarliy the first 28 or the last 28 of them. How this can be done ?Thank you.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |