Home > Net >  Regular Expression to find all shared libraries that end with /lib/ and not a subdir of that?
Regular Expression to find all shared libraries that end with /lib/ and not a subdir of that?

Time:08-02

I'm trying to get all shared libraries from a root location but only want to list the ones in /lib/* and not under another sub-directory as in /lib/some_subdir (to be clear /lib /usr/lib /usr/local/lib /whatever/lib are all okay if no subdir under it)

For bash I have:

find / -type f,l -regex '.*/lib/.*\.so\(\.\|$\).*'

But that catches the subdirs, how can I have it ignore those?

TIA!!

CodePudding user response:

.* in /lib/.*\.so maches including subdirs. Try to replace it to [^/]*

CodePudding user response:

Using find

$ find / -type f,l -regex '/\(\([^/]*/\) \)?lib/[a-z0-9.]*.so' 
  • Related