|
前几天用pkgfile来频繁查找哪些包提供XX文件。实在是觉得pkgfile的效率慢得可怕,很疑惑它为啥把files列表分散开来。于是写了一个脚本,把files列表整合在一起,能够快N倍地进行查找。
[php]
#!/bin/bash
#file: ~/pfile
config=/etc/pacman.conf
cache=/var/cache/pkgtools/lists
list=/var/tmp/pkgfilelists.gz
repos=$(sed -n 's/^\[\(.*\)\]/\1/p' $config | grep -v options)
help(){
echo "Usage:"
echo " $0 {--help|--update|FILE}"
echo
echo "This is a script to fast find a package contains FILE (regexp)."
echo "For first use, please run:"
echo " pkgfile --update"
echo "Then:"
echo " $0 --update"
}
update(){
mv -f "$list" "$list.old" &>/dev/null
for repo in $repos; do
cd "$cache/$repo" 2>/dev/null
[ $? -ne 0 ] && continue
echo "listing [$repo] ($(ls | wc -l) packages) ..."
for i in *; do
name="$repo/${i%-*-*}"
grep -v '%FILES%' "$i/files" | sed "s|^|$name: |" | gzip >> ${list}
done
done
}
if [ $# -eq 0 ]; then
help
exit 0
fi
case "$1" in
-u|--update)
update
;;
-h|--help)
help
;;
*)
zgrep "$1" "$list"
;;
esac
[/php]
用法很简单,首先用原装正版的pkgfile下载文件列表,然后运行这个脚本更新,接着就可以查找了。
[php]
20:42:06@laptop:~ $ sudo pkgfile --update
Updating [core] file list... Extracting [core] file list... Done
Updating [extra] file list... Extracting [extra] file list... Done
Updating [community] file list... Extracting [community] file list... Done
Updating [arch-games] file list... Extracting [arch-games] file list... Done
20:43:28@laptop:~ $ pfile --update
listing [core] (184 packages) ...
listing [extra] (2458 packages) ...
listing [community] (1915 packages) ...
listing [arch-games] (166 packages) ...
[/php]
一个查找的花费时间的对比:
[php]
20:44:39@laptop:~ $ time pkgfile tunctl
extra/uml_utilities
real 0m8.741s
user 0m8.119s
sys 0m0.143s
20:45:33@laptop:~ $ time pfile tunctl
extra/uml_utilities: usr/bin/tunctl
extra/vde2: usr/share/man/man8/vde_tunctl.8.gz
extra/vde2: usr/sbin/vde_tunctl
extra/vde2: usr/bin/vde_tunctl
real 0m0.941s
user 0m0.853s
sys 0m0.020s
[/php] |
|