Skip to content

Instantly share code, notes, and snippets.

@jessykate
Last active July 19, 2023 20:25
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 jessykate/4d6417c2ae80715ca65fdac088930de9 to your computer and use it in GitHub Desktop.
Save jessykate/4d6417c2ae80715ca65fdac088930de9 to your computer and use it in GitHub Desktop.
a "most recent" command showing file listing of mobi, pdf and epub across sub-directories sorted by time
# Show the most recent files of type mobi, pdf or epub, sorted with most recent at the bottom. Works on files and subdirectories of the current directory.
# Useful references:
# find -printf is not POSIX. `-printf` becomes `-print0 | xargs -0 stat -f`
# need to convert format specifiers as well.
# '%A@ %Ab %Ad %AY %AH:%AM || %P' shows last access time in seconds since the epoch. the month, day, year and time, a "||" separator, then filename.
# POSIX's `find` printf arguments: https://man7.org/linux/man-pages/man1/find.1.html
# POSIX version (Linux)
alias mr="find . -type f \( -iname '*.pdf' -o -iname '*.mobi' -o -iname '*.epub' \) -printf '%A@ %Ab %Ad %AY %AH:%AM || %P \n' | sort -n | cut -f2- -d\" \""
# Less pretty Mac OS version.
# `mra` version uses the %a argument to the stat command, showing most recently accessed.
# `mrm` version uses the %m argument to the stat command, showing most recently modified.
alias mra="find . -type f \( -iname '*.pdf' -o -iname '*.mobi' -o -iname '*.epub' \) -print0 | xargs -0 stat -f '%a %N' | sort -n"
alias mrm="find . -type f \( -iname '*.pdf' -o -iname '*.mobi' -o -iname '*.epub' \) -print0 | xargs -0 stat -f '%m %N' | sort -n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment