On Tue, Jun 04, 2013 at 07:12:38PM +1000, Andrew Spiers wrote:
> Is this the best way?
>
> dpkg -L python-docutils | xargs ls -dF | grep \*
>
> I used to do
>
> dpkg -L python-docutils | grep bin
# apt-get install dlocate
# dlocate -lsbin python-docutils
/usr/share/docutils/scripts/python2/rst2html
/usr/share/docutils/scripts/python2/rst2latex
/usr/share/docutils/scripts/python2/rst2man
/usr/share/docutils/scripts/python2/rst2odt
/usr/share/docutils/scripts/python2/rst2odt_prepstyles
/usr/share/docutils/scripts/python2/rst2pseudoxml
/usr/share/docutils/scripts/python2/rst2s5
/usr/share/docutils/scripts/python2/rst2xetex
/usr/share/docutils/scripts/python2/rst2xml
/usr/share/docutils/scripts/python2/rst-buildhtml
/usr/share/docutils/scripts/python2/rstpep2html
note that 'dpkg -L python-docutils | grep bin' wouldn't have found any
of the above executables, because they're not in a directory named bin/
disclaimer: dlocate is my package. worse, the '-lsbin' option parses the
output of ls.
it does, however, work because it's reasonably safe to assume GNU ls on
debian systems (and it really only prints out the filenames of normal -
non-directory/link/socket/device-node etc - files when there's an 'x' or
's' in the perms field of 'ls -lLd', anyway, which is predictable and
standard). it is also a lot faster than, e.g., running a for-loop around
stat.
the shell code in dlocate that implements -lsbin looks like this:
'-lsbin')
if [ -s $DPKG_INFO/$PKG.list ] ; then
dlocate -L $PKG | \
xargs -r ls -lLd 2> /dev/null | \
grep -v "^[^-]" | \
grep -E '^-.{2,8}[xs]' | \
sed -e 's/.* \//\//' | \
xargs -r ls -1
result=$?
else
echo Package $PKG not installed or $PKG.list is empty. >&2
result=1
fi
;;
i wrote that around fifteen years ago, and haven't looked at it
since....but looking at it now, i can see a number of ways to improve
it.
starting with (even though i haven't yet run into any packages with
spaces in the filenames) adding "-d '\n'" to both invocations of xargs
so that it uses \n as the delimeter rather than any whitespace. xargs
didn't have a '-d' option fifteen years ago.
and the 'grep | grep | sed' could be replaced with just a single call
to sed (at the cost of the script's readability). the first grep is
redundant, and the second grep can be merged into the sed script:
dlocate -L "$PKG" | \
xargs -d '\n' -r ls -lLd 2> /dev/null | \
sed -n -r -e '/^-.{2,8}[xs]/ s/.* \//\//p' | \
xargs -d '\n' -r ls -1
FYI, 'dlocate -L $PKG' just cats /var/lib/dpkg/info/$PKG.list - 'dpkg
-L' works as well. so there's a /usr/local/sbin/lsbin script for you if
you don't want to install dlocate. dlocate does a lot more than just
lsbin, though:
$ dlocate -h
Usage: dlocate [option...] [command] [PATTERN...]
Commands:
DEFAULT/none PATTERN list records that match either package or files names
-S PATTERN list records that match filenames
-L package list all files in package
-l package regexp-enhanced emulation of 'dpkg -l'
-s package print package's status
-ls package 'ls -ldF' of all files in package
-du package 'du -sck' of all files in package
-conf package list conffiles in package
-lsconf package 'ls -ldF' of conffiles in package
-md5sum package list package's md5sums (if any)
-md5check package check package's md5sums (if any)
-man package list package's man pages (if any)
-lsman package list full path/filenames of man pages
-lsbin package list full path/filenames of executable files
-K list installed kernel & related packages
-k detailed list of installed kernel & related packages
The -l, and -S commands are approximately the same as the equivalent dpkg
options except that the search is performed using regular expressions
rather than fixed strings.
Options
--filename-only only output file names when searching for files
--package-only only output package names when searching for files
Regular Expression Options (see grep(1) for details):
-E, --extended-regexp
-F, --fixed-strings
-G, --basic-regexp
-P, --perl-regexp
-w, --word-regexp restrict matches to whole words
-i, --ignore-case case-insensitive match
Miscellaneous Options:
-h, -H, --help display this help message and exit.
-V, --version display dlocate's version number and exit.
-v, --verbose, --debug verbose/debug output
craig
--
craig sanders <[email protected]>
_______________________________________________
luv-main mailing list
[email protected]
http://lists.luv.asn.au/listinfo/luv-main