Linux Shell Scripting: Recursively loop through directories and files

This only returns results from the directory: "dir" but I want results for all files in "dir" including all files in all subdirectories of "dir".
f in dir/*
do 
 echo File: $f
done

Open in new window

LVL 16
hankknightAsked:
Who is Participating?
 
woolmilkporcConnect With a Mentor Commented:
for f in $(find /path/to/qqq -type f)
do
 echo File: $f
done

To display just the filename without the path component:

...
echo File: $(basename $f)
...
0
 
ozoConnect With a Mentor Commented:
find dir -exec echo File:  {} \;
or
find dir -print | xargs -L1 echo File:
0
 
hankknightAuthor Commented:
How can I integrate that with my loop?  This does not work:
find qqq/ -exec echo File:  {}
do 
 echo File: $f
done

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.