glocate

faster locate using grep
git clone https://a3nm.net/git/glocate/
Log | Files | Refs | README

update (814B)


      1 #!/bin/bash
      2 
      3 # adapted from /etc/cron.daily/locate in the Debian locate package
      4 
      5 # http://stackoverflow.com/a/19622569
      6 trap 'exit' ERR
      7 
      8 DEST="/home/files"
      9 NFILES="8" # must be <9 because of split
     10 
     11 if which on_ac_power >/dev/null 2>&1; then
     12     ON_BATTERY=0
     13     on_ac_power >/dev/null 2>&1 || ON_BATTERY=$?
     14     if [ "$ON_BATTERY" -eq 1 ]; then
     15         exit 0
     16     fi
     17 fi
     18 
     19 # See ionice(1)
     20 if [ -x /usr/bin/ionice ] &&
     21     /usr/bin/ionice -c3 true 2>/dev/null; then
     22     IONICE="/usr/bin/ionice -c3"
     23 fi
     24 
     25 # http://unix.stackexchange.com/a/4849/
     26 flock --nonblock /run/glocate.daily.lock $IONICE \
     27   find / \( -type d -printf "%p/\n" , -type f -print \) |
     28   split -a 1 --numeric-suffixes=1 --additional-suffix=.tmp \
     29     - ${DEST}. -nr/$NFILES
     30 for a in `seq 1 $a`
     31 do
     32   # atomic
     33   mv "${DEST}.${a}.tmp" "${DEST}.${a}"
     34 done
     35