#!/bin/sh # prepends date to the filename unless it already exists. # path -> dirname/yyyy-mm-dd.basename date=$(date +%Y-%m-%d) for a in "$@" do base="$(basename "$a")" date_regexp='^[0-9]{4}-[0-9]{2}-[0-9]{2}' if ! echo "$base" | grep -E "$date_regexp" > /dev/null then dir="$(dirname "$a")" mv "$a" "$dir/$date.$base" fi done