/usr/bin/dlocate is in dlocate 1.02+nmu3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | #!/bin/bash
#
# original script by Jim Pick <jim@jimpick.com>, GPL'd of course
# many changes and enhancement by Craig Sander <cas@taz.net.au>
#
# hacked by cas to use case instead of if/elif/fi
# hacked by cas to add '-ls' option. also added error checking for
# -L and -ls options.
# hacked by cas to add '-conf' and '-lsconf' options.
# hacked by cas to add '-md5sum' and '-md5check' options.
# hacked by cas to add '-man' option.
# hacked by cas to add '-s' option (requires grep-dctrl).
# hacked by cas to support multiple string/package arguments
# hacked by cas to add simplistic emulation of 'dpkg -l'
DLOCATEDB=/var/lib/dlocate/dlocatedb
DPKGLIST=/var/lib/dlocate/dpkg-list
DPKG_INFO=/var/lib/dpkg/info
COMPRESS_DLOCATEDB='0'
GREP='grep'
[ -e /etc/default/dlocate ] && . /etc/default/dlocate
[ "$COMPRESS_DLOCATE" = "1" ] && GREP='zgrep'
function dlocate_help {
cat <<__EOF__
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
-- stop processing commands and options. remainder of
command-line is filename(s)
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
__EOF__
exit 1
}
function dlocate_version {
VERSION_BANNER="1.02"
echo "dlocate version $VERSION_BANNER"
exit 0
}
function dlocate_option_error () {
echo "dlocate: unknown option '$1'"
echo
echo "Use: 'dlocate -- $1' if you want to search for '$1'"
exit 1
}
OPTION="DEFAULT"
LAST_OPT=0
# default to extended regexp
RE_TYPE="-E"
DCTRL_RE_TYPE="-e"
RE_SEPARATOR="|"
# default to case-sensitive
IGNORE_CASE=""
# default to non- word-based searches
WORD_RE=""
# output filters for -S and DEFAULT option
OUTPUT_FILTER="none"
function output_filter() {
[ "$VERBOSE" = "1" ] && echo "OUTPUT FILTER: $OUTPUT_FILTER"
case "$OUTPUT_FILTER" in
("Filenames only")
cut -d\ -f 2 | sort -u
;;
("Packages only")
cut -d: -f 1 | sort -u
;;
(*)
cat
;;
esac
}
VERBOSE=0
SEPARATOR='::::::::'
PKGS=""
for p in "$@"; do
if [ "$LAST_OPT" -eq 1 ] ; then
PKGS="$PKGS$SEPARATOR$p"
else case "$p" in
('--')
LAST_OPT=1
;;
(''|'-h'|'-H'|'--help')
dlocate_help
;;
('-V'|'--version')
dlocate_version
;;
('-v'|'--verbose'|'--debug')
VERBOSE=1
;;
('-K'|'-k')
OPTION="$p"
PKGS="dummy"
;;
('-S'|'-L'|'-l'|'-s'|'-ls'|'-du'|'-conf'|'-lsconf'|'-md5sum'|'-md5check'|'-man'|'-lsman'|'-lsbin')
OPTION="$p"
;;
('-i'|'--ignore-case')
IGNORE_CASE='-i'
;;
('-E'|'--extended-regexp')
RE_TYPE='-E'
DCTRL_RE_TYPE='-e'
RE_SEPARATOR='|'
;;
('-F'|'--fixed-strings')
RE_TYPE='-F'
RE_SEPARATOR="\n"
;;
('-G'|'--basic-regexp')
RE_TYPE='-G'
DCTRL_RE_TYPE='-r'
RE_SEPARATOR='\\|'
;;
('-P'|'--perl-regexp')
RE_TYPE='-P'
RE_SEPARATOR='|'
;;
('-w'|'--word-regexp')
WORD_RE="-w"
;;
('--filename-only')
OUTPUT_FILTER='Filenames only'
;;
('--package-only')
OUTPUT_FILTER='Packages only'
;;
(-*)
dlocate_option_error $p
;;
(*)
PKGS="$PKGS$SEPARATOR$p"
;;
esac
fi
done
PKGS=$(echo "$PKGS" | sed -e "s/^$SEPARATOR//")
[ -z "$PKGS" ] && dlocate_help
PKGS_REGEXP=$(echo "$PKGS" | sed -e "s/$SEPARATOR/$RE_SEPARATOR/g")
FILES_REGEXP="($PKGS_REGEXP)"
[ "$WORD_RE" = "-w" ] && FILES_REGEXP="\b$FILES_REGEXP\b"
PKGS=$(echo "$PKGS" | sed -e "s/$SEPARATOR/ /g")
if [ "$VERBOSE" = "1" ] ; then
echo "PKGS:" $PKGS
echo "RE_SEPARATOR:" $RE_SEPARATOR
echo "PKGS_REGEXP:" $PKGS_REGEXP
fi
[ -z "$PKGS_REGEXP" ] && PKGS_REGEXP='^$'
if [ "$OPTION" = '-l' ] ; then
[ -z "$COLUMNS" ] &&
COLUMNS=$(stty -a 2>&- |
sed -ne '/columns/s/.*columns \([0-9]*\)[^0-9].*/\1/p');
[ 0"$COLUMNS" -lt 80 ] && COLUMNS=80;
((fieldw=(COLUMNS-24)/4));
# dpkg uses ((fieldd=fieldw*2+16));
#
# limiting the output to COLUMNS-2 characters and losing up to
# additional 3 characters due to the rounding error.
((fieldd=COLUMNS-fieldw*2-6));
fmt_eq=$(echo ==================================================== |
cut -c-$fieldw)
HEADER=$( printf \
"Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ %-${fieldw}s %-${fieldw}s %s
+++-${fmt_eq}-${fmt_eq}-${fmt_eq}${fmt_eq}==================\\n" \
Name Version Description)
BODY_FMT_STRING="%-2s %-${fieldw}.${fieldw}s %-${fieldw}.${fieldw}s %-${fieldd}.${fieldd}s\\n"
[ "$VERBOSE" = "1" ] && echo RUNNING: $GREP $RE_TYPE $WORD_RE $IGNORE_CASE -- "$PKGS_REGEXP" "$DPKGLIST"
BODY=$($GREP $RE_TYPE $WORD_RE $IGNORE_CASE -- "$PKGS_REGEXP" "$DPKGLIST" | \
awk -F'\t' "{ printf \"$BODY_FMT_STRING\", \$1, \$2, \$3, \$4 }" |
sed -e 's/ *$//g'
)
[ -n "$BODY" ] && echo -e "$HEADER\n$BODY"
elif [ "$OPTION" = '-S' ] ; then
if [ "$RE_TYPE" = '-F' ] ; then
echo "Error: -F Fixed String searches are incompatible with -S"
echo
exit 1
fi
PREFIX="^([-a-zA-Z0-9_.+]+:|diversion by )"
[ "$RE_TYPE" = "-G" ] && PREFIX="^([-a-zA-Z0-9_.+]+:\|diversion by )"
[ "$VERBOSE" = "1" ] && echo RUNNING: $GREP $RE_TYPE $IGNORE_CASE -- "$PREFIX.*$FILES_REGEXP" "$DLOCATEDB"
$GREP $RE_TYPE $IGNORE_CASE -- "$PREFIX.*$FILES_REGEXP" "$DLOCATEDB" | output_filter
result=${PIPESTATUS[0]}
elif [ "$OPTION" = 'DEFAULT' ] ; then
[ "$VERBOSE" = "1" ] && echo RUNNING: $GREP $RE_TYPE $IGNORE_CASE -- $WORD_RE "$PKGS_REGEXP" "$DLOCATEDB"
$GREP $RE_TYPE $IGNORE_CASE -- $WORD_RE "$PKGS_REGEXP" "$DLOCATEDB" | output_filter
result=${PIPESTATUS[0]}
elif [ "$OPTION" = '-s' ] ; then
DCTRL_REGEXP="^($PKGS_REGEXP)$"
[ "$VERBOSE" = "1" ] && echo RUNNING: grep-dctrl -X -P $DCTRL_RE_TYPE $DCTRL_REGEXP /var/lib/dpkg/status
grep-dctrl -P $DCTRL_RE_TYPE $DCTRL_REGEXP /var/lib/dpkg/status
result=$?
elif [ "$OPTION" = '-k' ] ; then
grep-status -P -e "(^linux-(image|source|headers|doc|debug)|nvidia-kernel-|.*-modules-)" | \
grep-dctrl -n -s Package -F status " installed" - | \
egrep -v -- '^(lib|openser|pam|scim|tryton|wims)|-perl'
result=$?
elif [ "$OPTION" = '-K' ] ; then
KERN_RE=$(dlocate -k | xargs | sed -e 's/ /|/g')
[ "$VERBOSE" = "1" ] && echo echo RUNNING: dlocate -P -l "\s($KERN_RE)\s"
dlocate -P -l "\s($KERN_RE)\s"
result=$?
else
for PKG in $PKGS; do
case "$OPTION" in
'-L')
if [ -s $DPKG_INFO/$PKG.list ] ; then
cat $DPKG_INFO/$PKG.list
result=$?
else
echo Package $PKG not installed or $PKG.list is empty. >&2
result=1
fi
;;
'-ls')
if [ -s $DPKG_INFO/$PKG.list ] ; then
xargs -r ls -ldF < $DPKG_INFO/$PKG.list
result=$?
else
echo Package $PKG not installed or $PKG.list is empty. >&2
result=1
fi
;;
'-du')
if [ -s $DPKG_INFO/$PKG.list ] ; then
du -sck $(cat $DPKG_INFO/$PKG.list | xargs -r ls -1dF | grep -v "@$\|/$" )
result=$?
else
echo Package $PKG not installed or $PKG.list is empty. >&2
result=1
fi
;;
'-conf')
if [ -s $DPKG_INFO/$PKG.conffiles ] ; then
cat $DPKG_INFO/$PKG.conffiles
result=$?
else
echo Package $PKG not installed or has no conffiles. >&2
result=1
fi
;;
'-lsconf')
if [ -s $DPKG_INFO/$PKG.conffiles ] ; then
ls -ldF $(cat $DPKG_INFO/$PKG.conffiles)
result=$?
else
echo Package $PKG not installed or has no conffiles. >&2
result=1
fi
;;
'-md5sum')
if [ -s $DPKG_INFO/$PKG.md5sums ] ; then
cat $DPKG_INFO/$PKG.md5sums
result=$?
else
echo Package $PKG not installed or has no md5sums. >&2
result=1
fi
;;
'-lsman')
if [ -s $DPKG_INFO/$PKG.list ] ; then
dlocate -L $PKG | \
grep -E '/man[0-9]+/'
result=$?
else
echo Package $PKG not installed or $PKG.list is empty. >&2
result=1
fi
;;
'-man')
if [ -s $DPKG_INFO/$PKG.list ] ; then
dlocate -L $PKG | \
grep -E '/man[0-9]+/' | \
sed -e 's/\.gz$//' \
-e 's:.*/::' \
-e 's/\(^.*\)\.\(.*\)/\2 \1/' | \
sort -u
result=$?
else
echo Package $PKG not installed or $PKG.list is empty. >&2
result=1
fi
;;
'-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
;;
'-md5check')
if [ -s $DPKG_INFO/$PKG.md5sums ] ; then
pushd / >/dev/null 2>&1
cat $DPKG_INFO/$PKG.md5sums | \
md5sum -c -
popd >/dev/null 2>&1
result=$?
else
echo Package $PKG not installed or has no md5sums. >&2
result=1
fi
;;
esac
done
fi
test -n "$result" && exit $result
|