Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Linux Shell Scripting: Recursively loop through directories and files

Posted on 2013-11-08
3
Medium Priority
?
492 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 85

Assisted Solution

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

Author Comment

by:hankknight
ID: 39634301
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 1800 total points
ID: 39634364
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

971 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