Skip to main content

How do I use nm to recursively search for specific symbol? [Resolved]

I would like to find the symbol "start" for example in all object files recursively down from the directory I'm in. I think I can use nm or readelf, but I'm new to shell and not understanding how to do this from the manual.

Question Credit: Andrew Cina
Question Reference
Asked September 21, 2019
Tags: nm
Posted Under: Unix Linux
1 Answers

You could use something like this:

find . -type f \( -executable -o -name \*.o \) -exec nm -A {} + | grep start

This will find all executable files, or object files, and run nm -A on them, piping the results to grep.

You can adjust this to look for other files. For libraries (.so etc.) you should use nm -A -D (to list dynamic symbols). The -A option makes nm repeat the file name on every line, so that the filtered output is still useful.

credit: Stephen Kitt
Answered September 21, 2019
Your Answer