Use find to find last file

This commit is contained in:
Antonio J. Delgado 2024-12-14 15:29:43 +02:00
parent 9e80fe7fb4
commit f71dac44dd

View file

@ -3,11 +3,11 @@ while read -r dir
do do
if [ -n "${dir}" ]; then if [ -n "${dir}" ]; then
echo "Checking dir '${dir}'..." echo "Checking dir '${dir}'..."
last_file="${dir}/$(ls -ht -- "${dir}/" | grep \.webm\.download_info\.json | head -n1)" last_file="$(find "${dir}/" -type f -printf "%T@ %p\n" | sort -n | grep \.webm\.download_info\.json | head -n1 | sed 's/^[0-9\.]* //')"
if [ "${last_file}" == "${dir}/" ]; then if [ "${last_file}" == "${dir}/" ] || [ -z "${last_file}" ]; then
last_file="${dir}/$(ls -ht -- "${dir}/" | head -n1)" last_file="$(find "${dir}/" -type f -printf "%T@ %p\n" | sort -n | head -n1 | sed 's/^[0-9\.]* //')"
fi fi
if [ "${last_file}" == "${dir}/" ]; then if [ "${last_file}" == "${dir}/" ] || [ -z "${last_file}" ]; then
echo "Skipping, no file found in dir" echo "Skipping, no file found in dir"
else else
echo "Last modified file is '${last_file}'" echo "Last modified file is '${last_file}'"