#!/bin/sh # # Format the output from "find -type f -ls" # usage() { echo "usage: $(basename $0) [-d]" >&2 exit 1 } while getopts ":d" c do case "$c" in d) pdate=1;; :|'?') usage;; esac done if [ $OPTIND -le $# ]; then usage; fi nawk ' { size = $7; date = sprintf("%3s %2s %5s", $8, $9, $10) path = substr($0, index($0, date) + 13); gsub(/\\ /, " ", path) i = match(path, /\/[^\/]+$/) dir = substr(path, 1, i - 1); file = substr(path, i + 1) printf "%s\t%s\t%s\t%s\n", dir, file, size, date }' | sort -f | nawk -v pdate=$pdate ' BEGIN { FS = "\t"; for (i = 0; i < 79; i++) hdrline = hdrline "-" } { if ($1 != olddir) { if (notfirst) printf "\n" printf "%s\n%s\n%s\n", hdrline, $1, hdrline olddir = $1; notfirst = 1 } if (pdate) printf "%-54s %9s %s\n", $2, $3, $4 else printf "%-68s %9s\n", $2, $3 } END { printf "\n%d %s found.\n", NR, (NR == 1) ? "item" : "items" }' .