2

I'm trying to find a way to let the find command only find files, that could possibly have a shared library dependency (meaning they produce output when called with ldd).

To find all dependencies of a group of files (binaries, text, office, etc.), I go through them with find . -type f and call ldd on all of them, then parse the output.

I know that find has the -executable test option, but I'm not sure, if that covers all my bases.

I know that ldd gives output similar to "The Program isn't dynamically linked" , but I would like to save myself the command, for files which cannot have shared libraries.

  • 4
    Please note, that ldd displays only dependencies at compile time for (mainly?) ELF binaries. At runtime, e.g. python scripts can load shared libraries and therefore "depend" on them. – jofel Oct 24 '14 at 10:14
  • That's a good point. I'm happy with only the libraries, that ldd gives me at this moment. Thanks for your time. – Minix Oct 24 '14 at 10:17
1

ldd dumps the dependencies of Elf files. All Elf files start with the bytes \x7F 'E' 'L' 'F', which is probably the fastest way to test them. However, I'm not aware of any option in find which reads the content of the file. find mainly just looks at the metadata in the directory listing, like filename, mode bits, and so on.

However, in order to run an Elf file it must have its Execute bit set. If you do have an Elf file with no execute bit, it can't be executed, so you probably don't care about it. So if you're looking for a quick way to speed up your search, checking for the execute bits should be safe.

I recommend -perm /555 instead of -executeable, because the first checks for any execute bit, and the second checks whether the current user can execute it.

But, in addition to dynamic languages like Python like jofel mentioned, many C programs will dynamically link against the PAM libraries (/lib/security/pam_*.so) and the libc "nss" libraries (/lib/libnss*.so). If you're building a chroot or something, you need these.

  • Is it not possible for *.so files to also have dependencies and not be executable? Thanks for your answer. – Minix Oct 30 '14 at 10:12
  • On every system I have access to, the .so files have their execute bit set. However I just tested, and indeed, they can be loaded even if they don't. So, for the case of a standard Gnu/Linux distro it should still be safe to use -perm /555, but for custom linuxes you might have to be careful. – M Conrad Oct 30 '14 at 23:36

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.