Last active
July 20, 2020 23:51
-
-
Save irisdyoung/dade32a74859b3ddb128d3337177b050 to your computer and use it in GitHub Desktop.
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 | |
# @idyoung 2020.07.20 | |
# Use this script in place of `ls` to list directories in a format 06Jun2020 in chronological order | |
export matches=`ls | grep "^[0-9][0-9][[:alpha:]][[:alpha:]][[:alpha:]][0-9][0-9][0-9][0-9]"` | |
export prefixed_matches="" | |
for match in $matches; do | |
export day=${match:0:2} | |
export month_alpha=${match:2:3} | |
case $month_alpha in | |
"Jan") | |
export month="01" | |
;; | |
"Feb") | |
export month="02" | |
;; | |
"Mar") | |
export month="03" | |
;; | |
"Apr") | |
export month="04" | |
;; | |
"May") | |
export month="05" | |
;; | |
"Jun") | |
export month="06" | |
;; | |
"Jul") | |
export month="07" | |
;; | |
"Aug") | |
export month="08" | |
;; | |
"Sep") | |
export month="09" | |
;; | |
"Oct") | |
export month="10" | |
;; | |
"Nov") | |
export month="11" | |
;; | |
"Dec") | |
export month="12" | |
;; | |
*) | |
echo "cannot interpret argument $match" | |
export month="13" | |
;; | |
esac | |
export year=${match:5:4} | |
if [ $month != "13" ]; then | |
export prefixed_matches="${prefixed_matches} ${year}${month}${day}_${match}" | |
fi | |
done | |
echo $prefixed_matches | sed "s: :\n:g" | sort | sed "s:.*_::" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment