Last active
July 30, 2020 23:02
-
-
Save craigforr/bbc3df25f0fb40720ce8934832d62a9f to your computer and use it in GitHub Desktop.
Finds the most recent files in the current directory tree
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
function findr() { | |
# Find recently modified files in the current directory tree | |
SEARCH_PATH='./*' | |
NUMBER_OF_RESULTS=20 | |
while [[ $# -gt 0 ]]; do | |
case "$1" in | |
-h|--help) | |
DISPLAY_USAGE=TRUE | |
shift | |
;; | |
-a|--all) | |
SEARCH_PATH="." | |
shift | |
;; | |
-c|--count) | |
NUMBER_OF_RESULTS=$2 | |
shift | |
shift | |
;; | |
esac | |
done | |
if [[ "$DISPLAY_USAGE" == 'TRUE' ]]; then | |
echo "Usage: findrecent [-c|--count NUMBER] [-a|--all]" | |
echo "Finds the most recent files in the current directory tree." | |
echo "" | |
echo "Optional arguments:" | |
echo "-a, --all Show results in hidden directories. Default is omit." | |
echo "-c, --count Number of results to display. Default is 20." | |
echo "-h, --help Display usage instructions (this text)." | |
echo "" | |
echo "Example:" | |
echo " findrecent" | |
echo " findrecent -c 20" | |
echo " findrecent --all -c 10" | |
else | |
find $SEARCH_PATH -type f -printf "%T@\t%Tc\t%p\n" | sort -n -r | cut -f 2- | head -${NUMBER_OF_RESULTS} | |
fi | |
} | |
findr "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment