I am trying to traverse all directories under the current directory using a shell script. In each of those sub directories, there is a makefile and I want to execute it. Any idea how to do ?
1 Answer
Try with find :
find -iname makefile -execdir make -f {} \;
That will find every file named makefile (or Makefile, or whatever different case for word makefile, thanks to thiton) (recursively) and then launch make against it.
3 Comments
thiton
Slight improvement: "Makefile" is often used as well, so -iname might be more appropriate.
uyetch
Well I tried the above method and it didn't work. Perhaps I should have mentioned that the targets of the makefiles are in the subdirectories themselves. Hence I guess we need to manually traverse the subdirectories one by one to get it write (?) .
Cédric Julien
@Warangalite : try with
-execdir instead of -exec, it will change directory before executing the command.