libfind - Searches library files with keywords and paths from default values and /etc/ld.so.conf.
I made this utility along with binfind. It also has had lots of improvements since then.
This script can be used to search files contained in library files (*.so, *.la, *.a, etc.) based from keywords provided. Along with a custom list of default paths, it will search for libraries inside directories that are specified in /etc/ld.so.conf. It would also examine files that are specified by the "include" directive in it.
After preparations it would search for the files that match all the provided keywords and show them to the user in plain format.
Usage: /usr/local/bin/libfind <partstring> [partstring2, ...]
I favor placing those scripts in /usr/local/bin. That usage instruction there is an output of the script when no argument is passed unto it.
Example output:
Note: It's not necessary that keywords are not intersective.
Get the updated version of this script here.
This script can be used to search files contained in library files (*.so, *.la, *.a, etc.) based from keywords provided. Along with a custom list of default paths, it will search for libraries inside directories that are specified in /etc/ld.so.conf. It would also examine files that are specified by the "include" directive in it.
After preparations it would search for the files that match all the provided keywords and show them to the user in plain format.
Usage: /usr/local/bin/libfind <partstring> [partstring2, ...]
I favor placing those scripts in /usr/local/bin. That usage instruction there is an output of the script when no argument is passed unto it.
Code:
#!/bin/bash # Check bash version. [[ BASH_VERSINFO -ge 3 ]] || { echo "$0: You need bash version 3.0 or higher to run this script." >&2 exit 1 } # LIBPATH Variable. You could add or remove default path values here. LIBPATHS=('/lib' '/usr/lib' '/usr/local/lib') # Functions function getabspath { local -a T1 T2=() local -i I=0 local IFS=/ A if [[ $1 == /* ]]; then read -a T1 <<< "$1" else read -a T1 <<< "$PWD/$1" fi for A in "${T1[@]}"; do case "$A" in ..) [[ I -gt 0 ]] && unset T2\[--I\] continue ;; .|'') continue ;; esac T2[I++]=$A done if [[ $1 == */ ]]; then if [[ I -ne 0 ]]; then __="/${T2[*]}/" else __=/ fi elif [[ I -ne 0 ]]; then __="/${T2[*]}" else __=/. fi } function getlibpaths { local FILE=$1 LINE [[ -f $FILE && -r $FILE ]] || return while read LINE; do case "$LINE" in /*) LIBPATHS[${#LIBPATHS[@]}]=$LINE ;; include\ *) local PATTERN=${LINE##include+([[:blank:]])} if [[ $PATTERN != /* ]]; then getabspath "$FILE" PATTERN=${__%/*}/${PATTERN} fi while read LINE; do getlibpaths "$LINE" done < <(compgen -G "$PATTERN") ;; esac done < "$FILE" } function main { # Set extended globbing. shopt -s extglob # Check arguments. [[ $# -eq 0 || "$1" == "-h" || "$1" == "--help" ]] && { echo "Usage: $0 <partstring> [partstring2, ...]" return 1 } # Prepare patterns. local A local -a IPATTERNS=(-iname "*$1*") for A in "${@:2}"; do IPATTERNS=("${IPATTERNS[@]}" -and -iname "*$A*") done # Prepare paths. getlibpaths "/etc/ld.so.conf" # Make list unique. local -a T=("${!LIBPATHS[@]}") local -i I=0 J C=${#T[@]} D=0 for (( ; I < C; ++I )); do for (( J = I + 1; J < C; ++J )); do [[ ${LIBPATHS[T[I]]} = "${LIBPATHS[T[J]]}" ]] && { unset LIBPATHS\[T\[J\]\] T\[J\] (( ++D )) } done [[ D -gt 0 ]] && { T=("${T[@]:I + 1}") (( C -= D + I + 1, I = -1, D = 0 )) } done # Remove unusable entries. for I in "${!LIBPATHS[@]}"; do [[ "${LIBPATHS[I]}" == @(|+([[:blank:]])) ]] && unset 'LIBPATHS[I]' done # Remove directories that do not exist, are not readable, or is not executable. for I in "${!LIBPATHS[@]}"; do [[ -d "${LIBPATHS[I]}" && -r "${LIBPATHS[I]}" && -x "${LIBPATHS[I]}" ]] || unset 'LIBPATHS[I]' done # Find. [[ ${#LIBPATHS[@]} -gt 0 ]] && find "${LIBPATHS[@]}" -maxdepth 1 -xtype f "${IPATTERNS[@]}" 2>/dev/null } # Start main "$@"
Code:
# libfind kde games /usr/lib64/libkdegames.so /usr/lib64/libkdegames.so.5 /usr/lib64/libkdegames.so.5.1.0
Get the updated version of this script here.
Total Comments 0