Skip to content

Instantly share code, notes, and snippets.

@rcastill
Last active January 9, 2025 22:07
Show Gist options
  • Save rcastill/761552abcef6bff2823220c531a065d0 to your computer and use it in GitHub Desktop.
Save rcastill/761552abcef6bff2823220c531a065d0 to your computer and use it in GitHub Desktop.
Get the latest version of a library installed in a linux system
#!/bin/bash
# Get the latest version of a library installed in a linux system.
# Usage: ./libver.sh lib
# Example: ./libver.sh cuda
# Explain: search for lib$lib.so in the system, then extract version from name.
# This assumes that the library "lib" can be found under /usr as: /path/to/liblib.so.x.y.z
if [ -z "$1" ]; then
>&2 echo "Usage: $0 lib"
exit 1
fi
lib="$1"
set -o pipefail
find /usr -name "lib$lib.so*" | sed -e "s/.*lib$lib.so.\(.*\)/\1/g" | grep "^[0-9.]*$" | sort | tail -n 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment