for file in *; do echo $file; yearmonth=$(echo $file | grep -o '[0-9][0-9][0-9][0-9]-[0-9][0-9]') newfilename=$(echo $file | grep -o '[0-9][0-9]-[a-z].*.md$') mkdir $yearmonth mv $file $yearmonth/$newfilename done