Last active
January 22, 2025 19:20
-
-
Save brwyatt/c21a888d79927cb476a4 to your computer and use it in GitHub Desktop.
BASH script to find the newest file under a directory structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ "x${1}" == "x" ]]; then | |
dir="." | |
else | |
dir="${1}" | |
fi | |
# Based on https://stackoverflow.com/questions/10575665/linux-find-command-find-10-latest-files-recursively-regardless-of-time-span | |
# with additions to return only the date of the newest file | |
find "${dir}" -type f -printf "%C@ %p\n" | sort -rn | head -n 1 | cut -d' ' -f2 | xargs ls -l -t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment