Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find all directories within a directory beginning with a particular prefix?

Tags:

bash

shell

Using a shell script, I'd like to find all directories within a directory (not recursively) that begin with a particular prefix, then loop through them. Pseudocode 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');
}
like image 269
Jake Petroules Avatar asked Feb 23 '23 14:02

Jake Petroules


1 Answers

for dir in "/etc/build/project-build-"*/
do
  do_something_with "$dir"Makefile
done
like image 183
Ignacio Vazquez-Abrams Avatar answered Apr 28 '23 08:04

Ignacio Vazquez-Abrams