1

I've been trying to find a particular shared object within ./lib/ using the 'find' utility in the bash shell. To be more specific, to find this shared object I wanted to find all files that started with 'lib'. Here's a list, for example.

libpango-1.0.so.0  
libpango-1.0.so.0.3600.8 
libpangocairo-1.0.so.0
libpangocairo-1.0.so.0.3600.8
libpangoft2-1.0.so.0
libpangoft2-1.0.so.0.3600.8
libpangoxft-1.0.so.0
libpangoxft-1.0.so.0.3600.8    

I tried using the -name option with the pattern 'lib.*', but none of the results I was looking for came up. Rather, several files from different directories & subdirectories were printed, whatnot. To be more specific, I typed this into the terminal:

find . -name 'lib.*' -print

Where exactly did I go wrong? What can I do to improve my pattern?

On another note, I'm using bash.

  • 1
    Try find . -name 'lib*' instead. – cuonglm Jun 19 '15 at 1:14
  • 1
    To elaborate a little, the argument to -name is a shell pattern, not a regular expression. – garyjohn Jun 19 '15 at 1:35
  • Still no results, unfortunately. I tried on another terminal, and got the same result - nothing at all. :( Even tried different variations, such as: find . -name 'lib.*', find . -name 'lib.*', and find . -name '^lib.*' to no avail. – Charybdis Jun 19 '15 at 1:36
  • 1
    Do you really mean ./lib/ (a lib directory below the current directory, .) - or are you trying to search /lib/ or perhaps /usr/lib/? – steeldriver Jun 19 '15 at 1:55
  • 1
    find ./lib -name 'lib*' or regex: find ./lib -regex '^lib.*'. If you are searching elsewhere, replace ./lib to path to the diretory you are searching for. – Arthur2e5 Jun 19 '15 at 2:21
2

You try to use a regex in your find command. To use a regex, you need the parameter -regex or you could use awk and find to find all files that started with lib.

find /usr/lib -type f | awk -F'/' '$NF ~ /^lib/'

Example

$ find /usr/lib -type f | awk -F'/' '$NF ~ /^lib/'
/usr/lib/mate-settings-daemon/libhousekeeping.so
/usr/lib/mate-settings-daemon/libkeyboard.so
/usr/lib/mate-settings-daemon/libxrdb.so
/usr/lib/mate-settings-daemon/libbackground.so
/usr/lib/mate-settings-daemon/libkeybindings.so
/usr/lib/mate-settings-daemon/libmedia-keys.so
/usr/lib/mate-settings-daemon/libclipboard.so
/usr/lib/mate-settings-daemon/libmouse.so
/usr/lib/mate-settings-daemon/libmpris.so
/usr/lib/mate-settings-daemon/libxsettings.so
/usr/lib/mate-settings-daemon/liba11y-settings.so
/usr/lib/mate-settings-daemon/liba11y-keyboard.so
/usr/lib/mate-settings-daemon/libsound.so
/usr/lib/mate-settings-daemon/libxrandr.so
/usr/lib/mate-settings-daemon/libtyping-break.so

Or without a regex:

find /usr/lib -type f -name "lib*"

Example

$ find /usr/lib -name "lib*"
/usr/lib/mate-settings-daemon/libhousekeeping.so
/usr/lib/mate-settings-daemon/libkeyboard.so
/usr/lib/mate-settings-daemon/libxrdb.so
/usr/lib/mate-settings-daemon/libbackground.so
/usr/lib/mate-settings-daemon/libkeybindings.so
/usr/lib/mate-settings-daemon/libmedia-keys.so
/usr/lib/mate-settings-daemon/libclipboard.so
/usr/lib/mate-settings-daemon/libmouse.so
/usr/lib/mate-settings-daemon/libmpris.so
/usr/lib/mate-settings-daemon/libxsettings.so
/usr/lib/mate-settings-daemon/liba11y-settings.so
/usr/lib/mate-settings-daemon/liba11y-keyboard.so
/usr/lib/mate-settings-daemon/libsound.so
/usr/lib/mate-settings-daemon/libxrandr.so
/usr/lib/mate-settings-daemon/libtyping-break.so
1

If you are trying to find out if a particular library is installed, you can also use rpm

rpm -qa | grep lib

The installed packages usually are in /usr/lib or /usr/lib64 (for 64 bit version). So you can also do

ls /usr/lib | grep lib

Or the find utility you were using

find /usr/lib -name "lib*"

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.