3

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 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Slight improvement: "Makefile" is often used as well, so -iname might be more appropriate.
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 (?) .
@Warangalite : try with -execdir instead of -exec, it will change directory before executing the command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.