How to find all directories in a directory starting with a specific prefix?

Using a shell script, I would like to find all directories within a directory (not recursively) that start with a specific prefix and then scroll through them. Pseudo-code example:

array directories = find('/etc/build', 'project-build-*'); foreach (string directory in directories) { // directory == 'project-build-example-x64' do_something_with('/etc/build/' + directory + '/Makefile'); } 
+4
source share
2 answers
 for dir in "/etc/build/project-build-"*/ do do_something_with "$dir"Makefile done 
+5
source

Here is an alternative with find and xargs

 find /etc/build/project-build-*/ -maxdepth 1 -name Makefile | xargs do_something 
+1
source

All Articles