How to Use ldd Command in Linux?

In Linux, the “ldd (List Down Dependencies)” command-line tool lists down the required shared libraries by each program or the specified command. It also found the missing dependencies/libraries of an executable program or the command. The “libraries” indicate resources such as classes, functions, values, or subroutines. 

This guide provides a deep insight into the working and functionality of the “ldd” Linux command. 

Prerequisites: Install the “ldd” Utility

The “ldd” command line utility is pre-installed in all the commonly used Linux distributions. But if you are using a very old distribution, install it by executing the following command:

$ sudo yum install libc-bin                         #For CentOS/RHEL
$ sudo dnf install libc-bin                         #For Fedora
$ sudo apt install libc-bin                         #For Ubuntu/Debian

The output displays that the “libc-bin” is already the newest version (2.35-0ubuntu3.1). 

How to Use the “ldd” command in Linux?

The working of the “ldd” command is based on its syntax, which is written below:

Syntax:

$ ldd [option]... file...

The syntax contains the following components:

  • ldd: Identifies the “ldd” command.
  • option: Represents the supported option of the “ldd” command.
  • file: specified file whose dependencies need to be checked.

The “ldd” command supports a list of useful arguments/options that can be easily accessed by executing its “–help” command:

$ ldd --help

The above output displays the options list and the basic information of the “ldd” command.

Example 1: Supports Only Absolute Path 

As the “ldd” command does not work on the standard command. It displays the following results shown in the screenshot if the user types the standard command with “ldd”:

$ ldd ls

Now, enter the “absolute” path of the “ls” command with “ldd” in this way:

$ ldd /usr/bin/ls

The output prints the shared libraries dependencies of the “ls” command.

Note: To get the absolute path of a particular command, run the “which” command that is mentioned here:

$ which ls

Example 2: Display Shared Library Dependencies

Execute the “ldd” command to display the shared library dependencies of an executable program or a command:

$ ldd /bin/grep

For more details of these dependencies use the “-v(verbose)” flag with the above “ldd” command as shown below:

$ ldd -v /bin/grep

The output now shows version information of the “grep” command shared library dependencies.

Example 3: Show the Un-Used Direct Dependency 

The “-u” argument of the “ldd” command displays the unused direct dependencies of the specified command. 

In this example, it displays the unused direct dependencies of the “cat” command:

$ ldd -u /usr/cat

The output prints nothing, which means that there are no unused direct dependencies of the “cat” executable command.

Example 4: Show Missing Dependencies With ldd

 The “ldd” command is also beneficial for finding out the missing dependencies of an executable file. In this scenario, the missing dependencies of the “rm” command are found in this way:

$ ldd /bin/rm

The missing dependencies of the “rm” command are displayed here.

Conclusion

The “ldd” command stands for “List Down Dependencies”, which displays executable files or program-shared library dependencies. It also prints the “unused” and “missing” dependencies. In addition, It does not work with standard commands until its absolute path is not defined. This guide has illustrated the objective, working, and purpose of the “ldd” Linux command.