Solved

Linux Shell Scripting: Recursively loop through directories and files

Posted on 2013-11-08
3
442 Views
Last Modified: 2013-11-08
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

0
Comment
Question by:hankknight
3 Comments
 
LVL 84

Assisted Solution

by:ozo
ozo earned 50 total points
Comment Utility
find dir -exec echo File:  {} \;
or
find dir -print | xargs -L1 echo File:
0
 
LVL 16

Author Comment

by:hankknight
Comment Utility
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
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 450 total points
Comment Utility
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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now