facelordgists
11/1/2018 - 12:00 AM

When you download a file or add it to your system, it stamps it with that date and time.

When you download a file or add it to your system, it stamps it with that date and time.

#!/bin/sh
filepath="test.txt"

added_date__year_month_day=$(mdls -name kMDItemFSName -name kMDItemDateAdded -raw "$filepath" | awk '{print $1}')
echo $added_date__year_month_day
#2017-12-10

added_date__year_month=$(mdls -name kMDItemFSName -name kMDItemDateAdded -raw "$filepath" | awk '{print $1}' | cut -c1-7)
echo $added_date__year_month
# 2017-12

added_date__year=$(mdls -name kMDItemFSName -name kMDItemDateAdded -raw "$filepath" | awk '{print $1}' | cut -c1-4)
echo $added_date__year
# 2017