#!/bin/sh
# find dead ids

. fslver

Usage() {
	ProgName=`basename "$0"`
	echo "find unused or bad file ids
Usage: $ProgName [[-r] [-f] paths(s) ...]

If no path(s) specified then the currrent directory is assumed."
	exit
}

for arg
do
	case "$arg" in
	-h|--help|-help)
		Usage ;;
	-v|--version)
		Version ;;
	*)
		argsToPassOn="$argsToPassOn $arg" ;;
	esac
done

set -f #no globbing
. getfpf "$argsToPassOn"

reUsers="`cut -f3 -d: /etc/passwd | tr '\n' '|'`0"
reGroups="`cut -f3 -d: /etc/group | tr '\n' '|'`0"
find $findArgs -printf "%U:%G:$FPF\0" |
tr '\n\0' '\1\n' |
grep -Ev "^($reUsers):($reGroups):" |
cut -d: -f3- |
tr '\n\1' '\0\n' |

#Note this find command is equivalent to the above.
#However it's much slower. This really shows the
#advantage of the small cohesive tools paradigm.
#find $findArgs \( -nouser -o -nogroup \) -printf "$FPF\0" |

if [ -p /proc/self/fd/1 ]; then
    cat
else
    xargs -r0 ls -lUdb --color=auto --
fi
