Since I often get side-tracked and forget what I was doing, I wrote a
script to find directories with recent (or otherwise selected) files
in them. That makes a better list than sorting directories by their
own modification times.
This script, 'finddirs_by_latest_file', allows to restrict the search
with extra find expression terms, but I usually just run the second
script below, 'fblf100', which invokes finddirs_by_latest_file to make
two lists; for the latest 5 and 100 days (or whatever time periods
given). Excuse all the script boilerplate.
Carlos, this may help you find your router config info.
--<cut>------------------------------------------------------------------
#!/bin/sh
# finddirs_by_latest_file.sh 2022-06-30 rw
#
# Outputs a list of directories of found files, sorted by the time of
# their most recently modified file, and prefixed by a file count.
#-----<lib/s/template-errx-getopts.sh>-----------------------------------
CMD=finddirs_by_latest_file
VERSION=0.1
export LC_COLLATE='C'
Cmd=`basename "$0"`
umsg() {
#------<USAGE>---------------------------------------------------------
printf 'usage: %s %s\n' \
"$Cmd" '[--sdir] [find_options] <find_starting_point>... [find_expression]' \
'' '' \
'The' 'find_expression, if any, is prepended to an implied:' \
' -type f' '-exec...'
}
errmsg() {
# usage: errmsg [msg_line ...]
test 1 -le "$#" || return 0
printf "${Cmd}: %s\\n" "$@" >&2
}
usage() {
# for output to stderr, and error exit: usage [msg_line ...]
# for normal exit: usage help
if [ x"$*" = x'help' ] ;then
umsg ;exit
else
errmsg "$@" ;umsg >&2 ;exit 2
fi
}
errx() {
# usage: errx <exitcode> [msg_line ...]
if expr x"${1-}" : x'[1-9][0-9]*$' > /dev/null ;then
ExCode="$1" ;shift
else
ExCode=3 ;set -- "$@" "$BUG: errx(): missing exit code"
fi
errmsg "$@" ;exit "$ExCode"
}
BUG="error: software bug"
errxbug() {
errx 3 "$BUG: $@"
}
exists() {
# usage: exists <path>
test -e "${1:?'exists(): null or missing arg'}" || test -h "$1"
# test -f "${1:?'exists(): null or missing arg'}" || test -d "$1" \
# || test -h "$1" || test -b "$1" || test -c "$1" || test -p "$1"
}
#------------------------------------------------------------------------
# Option defaults
SORT_BY_DIR_f=false
#XXX HACK: '--sdir' option is only recognized when it is first
if [ x"${1-}" = x'--sdir' ] ;then
SORT_BY_DIR_f=true
shift
fi
GOPTSTRING='hV'
while getopts ":$GOPTSTRING" OPT ;do
case "$OPT" in
#-----
h) usage help ;;
V) printf 'RW %s %s\n' "$CMD" "$VERSION" ;exit ;;
:) usage "missing argument for option: ${OPTARG}" ;;
\?) usage "invalid option: ${OPTARG}" ;;
*) errxbug "getopts optstring: option: ${OPT}" ;;
esac
done
shift `expr $OPTIND - 1`
if [ x"$SORT_BY_DIR_f" = x'true' ] ;then
sort_by() { sort -k 3 -k 2,2n ;}
else
# sort by time, then by dir (default)
sort_by() { sort -k 2,2n -k 3 ;}
fi
#------------------------------------------------------------------------
W=' *[^ ][^ ]* '
# find files: stat <seconds_since_Epoch> <path>
# sed: truncate last path component (to parent dir), use '.' if empty,
# or '/' if at root
# sort by dir, then by recent to old
# uniq: most recent of each dir. prefix with file count
# sort by time, then by dir (unless '--sdir' option: sort by dir)
# sed: remove seconds field
export TMPDIR=~/tmp
TEMPF=`mktemp --tmpdir "$CMD.XXXXXXXXXX.temp"` \
&& trap 'rm -f -- "$TEMPF"' EXIT \
|| exit
find -H "$@" -type f -exec stat -c '%Y %n' {} + > "$TEMPF" || exit
sed -e '
s+^\('"$W"'\)[^/]*$+\1.+
t
s+^\('"$W"'/\)[^/]*$+\1+
t
s+^\('"$W"'.*\)/[^/]*$+\1+
' "$TEMPF" \
|sort -k 2 -k 1,1nr \
|uniq -c -f 1 \
|sort_by \
|sed -e 's+'"$W"'+ +2'
--<cut>------------------------------------------------------------------
--<cut>------------------------------------------------------------------
#!/bin/sh
# fblf100 2021-12-07 rw
TOP=~
usage() {
printf 'usage: fblf100 [#_by_time_days [#_by_path_days]]' >&2
exit 2
}
{
printf '=== %s days, in order\n' "${1:-5}"
finddirs_by_latest_file "$TOP" -mtime -"${1:-5}" \
|| usage
printf '\n=== %s days, sorted\n' "${2:-100}"
finddirs_by_latest_file --sdir "$TOP" -mtime -"${2:-100}" \
|| usage
} \
|less
--<cut>------------------------------------------------------------------
--
Robert Webb