Given a root path, I am trying to loop through the sub-directories to loop through the files in each subdirectory and print the names of the files.
The directory structure is like this:
- Root directory
- dir2, - file{1..10}
 
- dir3, - file{1..10}
 
- dir4 - file{1..10}
 
 
I want to loop through dir2 and print all the filenames in it. Then loop through dir3 and print all the file names...and so on
Here is what I have so far:
#!/bin/bash
#!/bin/sh
cd /the/root/directory
for dir in */
do
        for FILE in dir
        do
             echo "$FILE"
        done > /the/root/directory/filenames.txt
done
This is the output I get in filenames.txt:
dir
My expected output is supposed to be:
file{1..10}
file{1..10}
file{1..10}
I am a beginner to bash scripting...well scripting in general. Any help is greatly appreciated!
 
     
     
     
    