How to find package for installed file in Brew?

后端 未结 6 589
囚心锁ツ
囚心锁ツ 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 14:09

    This function works for commands stored in the $( brew --prefix )/bin directory.

    function brew_find_pkg {
    
        cmds_to_search="$@"
        brew_bin=$( brew --prefix )/bin
    
        for cmd in $cmd_to_search ; do
    
            if [ -L $brew_bin/$cmd ] ; then
                \ls -l $brew_bin/$cmd |cut -f 2 -d '>'
            else
                echo "$cmd is not a brew command"
            fi
        done
    }
    

    E.g.:

    $ brew_find_pkg gawk gcc alskdfja
     ../Cellar/gawk/4.1.4_1/bin/gawk
     ../Cellar/gcc/5.3.0/bin/gcc
    alskdfja is not a brew command
    

提交回复
热议问题