From 074014ac306179b841487ece5f248ea3375411ce Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Sun, 4 Nov 2012 12:00:17 -0800 Subject: [PATCH] Bash script to prepend a file with the date --- bin/prefix-date | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 bin/prefix-date 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 +