#!/bin/sh _usage () { cat</dev/null 2>&1; then echo "'realpath' not found in PATH. Exiting." >&2 exit 1 fi for i ; do [ ! -d "$i" ] && continue ## We strip "./" from find's listing since we don't need it. We could avoid ## printing it in the first place, but there are several shortcomings: ## - Find over '.*' and '*', is bad practice since if will fail on ## non-existing files or for files beginning with a dash. ## - The 'printf' command in find is for GNU find only. ## 'LC_ALL=C sort' is required to make sure to output is consistent across ## different systems. ## The two following lines do the same for the same time cost. The former is shorter. # find "$i" -type f | awk -v str="$i" '{l=length(str)+2; print substr($0, l)}' | sort > "$OUTPUT" (cd -- "$i" && find . -type f) | sed 's/^.\///' | LC_ALL=C sort | \ if $opt_file; then i="$(realpath -- "$i")" base="${i##*/}" output="$base.index" [ -e "$output" ] && $opt_noclobber && output="$base-$(date +%F-%T).index" echo "$output" cat > "$output" else cat fi done