On 3/1/23 00:31, Robert Webb wrote:
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'
I didn't check what the part with uniq and sort_by is doing exactly. Still a minor hint: There's no need to call stat(1) again - because find(1) already has stat(3)-ed the file, and the -printf option allows to output the same information. This is a similar case than in the find manual (sorry if split on the next line): https://www.gnu.org/software/findutils/manual/html_node/find_html/Updating-A... stat(1): %Y time of last data modification, seconds since Epoch %n file name find(1): %p File's name. %Tk File's last modification time in the format specified by k, which is the same as for %A. and with k = '@': @ seconds since Jan. 1, 1970, 00:00 GMT, with fractional part. This makes something like this - which shows the 5 newest files: $ find -type f -printf '%T@:%p\n' | sort -k1,1n | tail -n5 | cut -d: -f 2- | xargs ls -ldog Of course, that only works for file names without newline '\n' in them, but that's a different discussion. Have a nice day, Berny