Skip to content

Instantly share code, notes, and snippets.

@mikedatsko
Created December 20, 2017 01:28
Show Gist options
  • Save mikedatsko/ce17a4246c1e6c2e6cb29115807eb4c9 to your computer and use it in GitHub Desktop.
Save mikedatsko/ce17a4246c1e6c2e6cb29115807eb4c9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
search_dir="../Pictures/untitled_folder"
for file in "$search_dir"/*
do
date_transfer=$(stat -f '%Sm' "$file")
filename=$(basename "$file")
extension="${filename##*.}"
new_name="$(date -j -f '%b %d %T %Y' "$date_transfer" '+%Y-%m-%d %H.%M.%S').$extension"
if [ -f "$file" ]
then
mv "$file" "$search_dir/$new_name"
echo "Renamed from: $file to: $search_dir/$new_name"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment