The Linux nm command is a utility for displaying the symbol table of an object file. It is a command line tool, which means it can be run from the terminal, and it is commonly used by programmers and developers to inspect the symbols defined in object files, such as executables, shared libraries, and object files generated by compilers.
To use the nm command, simply type nm followed by the name of the object file you want to inspect. For example, to display the symbol table of the ls executable, you would type:
nm /bin/ls
The nm command will then display the symbol table of the object file, with each symbol on a separate line. The output will include the address of the symbol, the type of the symbol, and the name of the symbol.
The nm command supports a number of options that allow you to control the format of the output and the information displayed. For example, the -t option allows you to specify the format of the symbol’s value, such as decimal, octal, or hexadecimal. The -C option allows you to display the symbol names in a demangled form, making them easier to read for human readers.
For example, to display the symbol table of the ls executable in hexadecimal format with demangled symbol names, you could use the following command:
nm -C -t x /bin/ls
This would display the symbol table of the ls executable in hexadecimal format, with demangled symbol names.
Another useful feature of the nm command is its ability to display only symbols of a specific type. The nm command uses a set of single-letter codes to represent the different types of symbols, such as T for global symbols, U for undefined symbols, and D for symbols that are marked as initialized data.
To display only symbols of a specific type, you can use the -s option followed by the symbol type code. For example, to display only global symbols from the ls executable, you could use the following command:
nm -s T /bin/ls
This would display only the global symbols from the ls executable, omitting all other symbol types.
In conclusion, the nm command is a valuable tool for displaying the symbol table of an object file. It allows you to control the format of the output and the information displayed, and it provides a number of options for filtering the symbols displayed. Whether you are a programmer or a developer, the nm command is a handy tool to have in your toolkit.