Skip to content

Instantly share code, notes, and snippets.

@devinnasar
Created July 19, 2017 19:37
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 devinnasar/9352bb8b4eb75e5ce0ed305b0b929cde to your computer and use it in GitHub Desktop.
Save devinnasar/9352bb8b4eb75e5ce0ed305b0b929cde to your computer and use it in GitHub Desktop.
# Gets the most recent directory under an s3 path
aws s3 ls "${_s3socpath}/tc-east-10/" | # list contents of s3 path
grep "PRE" | # filter for PRE (prefix) entries
awk '{printf $2"\n"}' | # print the second column of output (remove the PRE column)
sed 's/\/$//' | # cut the trailing slash off of paths
sort -r -n -t"-" -k1 -k2 -k3 | # sort the output: reverse, with a delimiter of hyphen ('-'), by the year, then month, then date
sed -n 1p # return the first line of output only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment