How to find package for installed file in Brew?

后端 未结 6 588
囚心锁ツ
囚心锁ツ 2020-12-23 13:37

How can I identify the package/formula for a given file, or a listing of all of a package\'s owned files, in Homebrew?

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-23 13:58

    Just wrote this dirty function to get you the brew package name a file belongs to:

    function brew_find_pkg {
        file_to_search="$@"
    
        for package in $(brew list); do
            brew ls $package | grep -E -q "/${file_to_search}$"
            if [ $? -eq 0 ]; then
                echo $package
                break
            fi
        done
    }
    

    Just type that in the terminal. And then to find to find the brew package a file belongs to, say the file gsed, just call the function like this

    brew_find_pkg gsed
    

    Note that the function will not work if you provide the full path of the file.

提交回复
热议问题