diff --git a/bin/prefix-date b/bin/prefix-date new file mode 100755 index 0000000..723ca6e --- /dev/null +++ b/bin/prefix-date @@ -0,0 +1,19 @@ +#!/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 +