Created
May 14, 2021 19:40
-
-
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
This file contains 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 | |
# | |
# 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