[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Specialized disk directory tools



>> On Fri 12 Sep 2025 at 07:20:39 (-0400), Richard Owlett wrote:

> Is there a similar page demonstrating "plocate"?  Thank you.

  You should already have the GNU version of "find" installed, but any system
  that's close to modern is probably fast enough to use a simple textfile
  and one or two scripts.  The main advantage of using a locate-style DB
  is that it's smaller than a plain-text file.

  Keeping a list of /dev or /proc files isn't that useful, so weed those
  out when you make your filelist.  To find your filesystem types:

    me% find $(mount | awk '{print $3}') -maxdepth 0 -printf "%F %p\n"
    zfs /
    devfs /dev
    procfs /proc
    fdescfs /dev/fd
    tmpfs /tmp
    zfs /home
    zfs /doc
    ...

  If your filesystems are ZFS, you could run this from cron once a day to
  generate a searchable list of files:

    #!/bin/bash
    #<updatedb: store useful filenames in a sorted list.

    export PATH=/bin:/usr/bin:/usr/local/bin
    set -o nounset
    tag=${0##*/}
    umask 022

    logmsg () { logger -t "$tag" "$@"; }
    die ()    { logmsg "FATAL: $@"; exit 1; }

    textdb='/var/tmp/locate/locate.txt'     # Configure to taste...
    dest=$(basename "$textdb")
    test -d "$dest" || mkdir -p "$dest" || die "$dest: not a directory"

    logmsg 'start find'
    find / -fstype zfs -print | sort > "$textdb"
    logmsg 'finish find'
    exit 0

  To search your list, the system "grep" works fine:

    #!/bin/bash
    #<locate: search list generated by updatedb.

    export PATH=/bin:/usr/bin:/usr/local/bin
    set -o nounset
    tag=${0##*/}
    umask 022

    logmsg () { echo "$(date '+%F %T') $tag: $@"; }
    die ()    { logmsg "FATAL: $@"; exit 1; }

    textdb='/var/tmp/locate/locate.txt'     # Configure to taste...
    test -f "$textdb" || die "$textdb: not found"

    case "$#" in
        0) die "need something to search for." ;;
        *) grep -i "$@" "$textdb" ;;
    esac

    exit 0

  You can also replace "grep" with (say) "ugrep", which absolutely flies.
  The script runs fine using a good-sized file list, even on spinning rust:

    me% wc /var/tmp/locate/locate.txt
      9436032   9551492 709665244 /var/tmp/locate/locate.txt

    me% time ./locate /run-testsuite
    /usr/ports/lang/gcc8/work/gcc-8.3.0/libvtv/scripts/run-testsuite.sh
    ./locate /run-testsuite  0.23s user 0.36s system 99% cpu 0.588 total

  HTH.

-- 
Karl Vogel                      I don't speak for anyone but myself

Homer:  I don't want you to see me sitting on my worthless butt.
Bart:   We've seen it, Dad.          --Homer Simpson, "Homer at the Bat"


Reply to: