LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1137|回复: 3

whichpkg: which package has installed the file?

[复制链接]
发表于 2004-2-20 11:51:44 | 显示全部楼层 |阅读模式

  1. #!/bin/bash
  2. #       whichpkg - list the slackware package(s) which installed
  3. #                       the given file or directory;
  4. #       syntax: whichpkg name [...]
  5. #
  6. #       starts with strict tests: full match on file or directory;
  7. #       if nothing found, try full match on .new or in;
  8. #       if nothing found, try substring match;
  9. #       multiple arguments are handled recursively.
  10. #
  11. # copyright 2004 by William Hunt, all rights reserved.
  12. # distributed under terms of the Gnu Public License, version 2 or later.
  13. # master distribution at [url]ftp://prv8.net/slackstuff/[/url]
  14. DATA=/var/log/packages/*
  15. [ "$1" = . ] || [ "$1" = .. ] && shift  # skip if given
  16. [ "${1:0:2}" = ./ ] && F=${1:2} || F=$1 # trim relative root if given
  17. [ "${1:0:1}" = / ] && F=${1:1}          # trim absolute root if given
  18. [ -z $F ] && exit                       # argument required
  19. x=$( grep ^$F$ ${DATA} )
  20. [ -z "$x" ] && x=$( grep ^$F/$ ${DATA} )
  21. [ -z "$x" ] && x=$( grep ^$F.new$ ${DATA} )
  22. [ -z "$x" ] && x=$( grep ^$F.in$ ${DATA} )
  23. [ -z "$x" ] && x=$( grep /$F/$ ${DATA} | grep -v ":.*:" )
  24. [ -z "$x" ] && x=$( grep /$F.new$ ${DATA} | grep -v ":.*:" )
  25. [ -z "$x" ] && x=$( grep /$F.in$ ${DATA} | grep -v ":.*:" )
  26. [ -z "$x" ] && x=$( grep /$F$ ${DATA} | grep -v ":.*:" )
  27. for a in $x ; do b=${a%:*} ; echo ${b##*/} ; done | uniq
  28. shift ; $0 $*   # recursion.
  29. # tha-tha-tha-that's all, folks!
复制代码
发表于 2004-3-8 14:31:36 | 显示全部楼层

a good utils

really useful
发表于 2004-3-11 16:51:53 | 显示全部楼层
太爽了,shell万岁!
发表于 2004-5-14 19:59:54 | 显示全部楼层

顶一个!

rt
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表