There are several ways to filter the output from locate
.
Method #1 - be explicit
If you know you're looking for a particular version of the library, then just ask locate
for it directly.
$ locate libstdc++-3-libc6.2-2-2.10.0.so
/usr/lib/libstdc++-3-libc6.2-2-2.10.0.so
Method #2 - grep
If you're looking for glibc .so libraries then use grep
to find only these results from locate
.
$ locate libstdc++ | grep ".so$"
/usr/lib/libstdc++-3-libc6.2-2-2.10.0.so
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/libstdc++.so
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/32/libstdc++.so
Method #3 - only return the first 10 lines of the result
If you're more interested in finding the first results, then use head
to return only the first few. You can direct head
to return different numbers of results using the -#
switch (shorter but non-standard equivalent of -n #
):
Example
$ locate glibc | head -8
/usr/lib64/glib-2.0/include/glibconfig.h
/usr/sbin/glibc_post_upgrade.i686
/usr/sbin/glibc_post_upgrade.x86_64
/usr/share/aclocal/glibc2.m4
/usr/share/aclocal/glibc21.m4
/usr/share/doc/glibc-2.12
/usr/share/doc/glibc-common-2.12
/usr/share/doc/glibc-2.12/BUGS
(note that it returns 8 lines, that's not necessarily the same as file paths as file paths can be made of several lines since the newline character is as valid as any in a file name).
locate
. You can use commands such asgrep
&head
to filter the output.