Skip to content

Instantly share code, notes, and snippets.

@rjurney
Created May 14, 2021 19:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rjurney/67296b4f5abea6caaebd8351de53c15b to your computer and use it in GitHub Desktop.
Save rjurney/67296b4f5abea6caaebd8351de53c15b to your computer and use it in GitHub Desktop.
Bash script for Mac OS X to find the latest files in a recursive path
#!/bin/bash
#
# I search recursively for the latest modified files. I work on Mac OS X. I am incredibly useful! Thanks cobbzilla!
#
# I come from https://stackoverflow.com/questions/5566310/how-to-recursively-find-and-list-the-latest-modified-files-in-a-directory-with-s#comment57080115_7448828
# Which was created by https://stackoverflow.com/users/1251543/cobbzilla
#
FILE_PATH=$1
FILE_COUNT=$2
# Path is required
if [ -z "${FILE_PATH}" ]; then
echo "Usage: latest <PATH> <optional:COUNT>"
kill -INT $$
fi
# Default file count option to 10
if [ -z "${FILE_COUNT}" ]; then
FILE_COUNT=10
fi
find "${FILE_PATH}" -type f -exec stat -f "%m %N" "{}" \; | sort -nr | head -${FILE_COUNT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment