bash best practice : scripting actions to be done in all current subdirectories
Hello!
I've been writing bash scripts which perform actions in all the subdirectories in a current directory. I've implemented this by executing a for loop which recurses over every subdirectory. My question is, how exactly should I obtain the names of the current subdirecties? What I've been doing is this ... Code:
for SUBDIR in `ls -d /*` ; do In the meantime, I've changed to using Code:
for SUBDIR in `find . -maxdepth 1 -mindepth 1 -type d` ; do Code:
alias subdirs='find . -maxdepth 1 -mindepth 1 -type d' Code:
for SUBDIR in `subdirs` ; do ... Any and all advice appreciated. Thanks! billywayne |
I don't know about best practice, but would this way be helpful?
Code:
find * -maxdepth 0 -type d -exec bash -c "cd \"{}\"; foo; bar" \; generate the whole list before doing anything. The reason for the quotes around the 'cd' parameter is that some directories may have spaces in the name. I was hoping to do something similar with the '-execdir' action on the find, but couldn't work out a way to make it only happen once on each subdirectory. |
thanks for the reply. i received an email when you replied two days ago, but strangely whenever I clicked on the link to view the thread, your reply wasn't showing up, until just now. weird.
i hadn't considered incorporating the commands directory into the 'find' command. It seems 'find' is more flexible than i had imagined. thanks again. |
Quote:
|
Quote:
|
All times are GMT -5. The time now is 08:57 PM. |