Skip to content

Instantly share code, notes, and snippets.

@craigforr
Last active July 30, 2020 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigforr/bbc3df25f0fb40720ce8934832d62a9f to your computer and use it in GitHub Desktop.
Save craigforr/bbc3df25f0fb40720ce8934832d62a9f to your computer and use it in GitHub Desktop.
Finds the most recent files in the current directory tree
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