Let's say you have a project structure with lots of Makefiles and there is a top level Makefile that includes all the other.

How can you list all the possible targets?

I know writing


and then tabbing to get the suggestions would generally do the trick, but in my case there are 10000 targets. Doing this passes the results through more and also for some reason scrolling the list results in a freeze. Is there another way?


This is how the bash completion module for make gets its list:

make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'

It prints out a newline-delimited list of targets, without paging.

  • 2
    Maybe add | sort -u to sort it and remove duplicates – BrainStone Apr 2 '17 at 21:25
  • like the | sort -u comment also – Mark Ch Oct 11 '18 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.