Traverse through directory....

hi

I have a directory structure like
Parent
Parent/child1/
Parent/child2/
Parent/child3/ and the each main directory contains

Parent/child1/file1.txt, Parent/child1/fil2.zip .......
Parent/child2/file1.txt,Parent/child/fil2.zip ......

Now i want to traverse to each and want to do cp that tfile to other location...
Parent/child1/file1.txt,
Parent/child1/fil2.zip
......
Parent/child2/subdir2/file1.txt,
Parent/child/subdir2/fil2.zip....
....................
So on

Not test, just give the clue for you.

find Parent -type f > filelist.log
for i in `cat filelist.log`
do
  DIR=`dirname $i`
  FILENAME=`basename $i`
  mkdir -p $DIR/subdir2
  cp $i $DIR/subdir2/$FILENAME
done

not sure, if I can put find command in for loop directly, will find command to list new create files in loop again?

for i in `find Parent -type f `
1 Like