Solved

Linux Shell Scripting: Recursively loop through directories and files

Posted on 2013-11-08
3
460 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
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 450 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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
digital ocean web console access ? does it use port 22 4 53
SSL/TLS - openssl troubleshooting 3 58
AWK: Pytthagoras bp script Part REVISITED 3 28
Shell script issue 4 53
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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 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.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

685 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