Skip to content

Instantly share code, notes, and snippets.

@pkozelka
Created December 29, 2020 04:52
Show Gist options
  • Save pkozelka/3b464da98b01b447a0f1c3c80ae541da to your computer and use it in GitHub Desktop.
Save pkozelka/3b464da98b01b447a0f1c3c80ae541da to your computer and use it in GitHub Desktop.
prefix filename with file's date
#!/bin/bash
# Indicated files will be renamed by prefixing with their modification date.
# Useful for photos from old devices that did not store metadata.
# This only prints the `mv` commands (preview); pipe it to `sh` to apply the changes
function filetime() {
local f=$1
local t=$(stat -c %y "$f")
t=${t%% *}
echo ${t//-/}
}
for i in "$@"; do
i2="$(filetime $i)-$i"
echo "mv $i $i2"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment