2014/10/17
Machine-readable Dates
I had some directories named in the format of “Jul 18, 2012”. Thanks, iPhoto export, but no thanks.
1
2
3
4
5
6
7
|
/bin/ls | while read dirnam; do
echo "$dirnam" | grep -Eq '^\w{3} \d{1,2}, \d{4}$'
if [ $? -eq 0 ]; then
newdir=`gdate -d "$dirnam" +%F`
mv -i "$dirnam" "$newdir"
fi
done
|
Note: gdate is GNU date after doing homebrew install coreutils
.
Update:
Some of the directories created where in the form “Jul 18, 2012-2”. In order to rename those as well I ran a subsequent command (don’t run this before the first invocation above – I don’t know how that will turn out):
1
2
3
4
5
6
7
|
/bin/ls | while read dirnam; do
echo "$dirnam" | grep -Eq '^\w{3} \d{1,2}, \d{4}'
if [ $? -eq 0 ]; then
newdir=`gdate -d "${dirnam%-2}" +%F`
mv -i "${dirnam}" "${newdir}-2"
fi
done
|
Machine-readable Dates is original content from devolve.