#!/usr/bin/env bash function datemv { if [[ $(basename "$1") == $(stat -c "%y" "$1" | cut -d " " -f1)* ]]; then echo "Do nothing with '$1'" else mv -v "$1" "$(dirname "$1")/$(stat -c "%y" "$1" | cut -d " " -f1)_$(basename "$1")" fi } if [ -d $1 ]; then for file in $(find "$1" -type f | grep -vP "\/\d{4}-\d{2}-\d{2}"); do datemv "$file" done else echo "Directory not found '$1'" exit fi