Skip to content

Instantly share code, notes, and snippets.

@brwyatt
Last active August 23, 2016 17:08
Show Gist options
  • Save brwyatt/c21a888d79927cb476a4 to your computer and use it in GitHub Desktop.
Save brwyatt/c21a888d79927cb476a4 to your computer and use it in GitHub Desktop.
BASH script to find the newest file under a directory structure
#!/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