Skip to content

Instantly share code, notes, and snippets.

@paulrobu
Created July 6, 2023 20:50
Show Gist options
  • Save paulrobu/eac3c1abb4a739194152e62b847bdd10 to your computer and use it in GitHub Desktop.
Save paulrobu/eac3c1abb4a739194152e62b847bdd10 to your computer and use it in GitHub Desktop.
Move photo files from current directory (e.g, Camera on Android phones) to newly created dated directories (e.g, 2023-07)
for f in *.jpg; do
#macos:
date=$(stat -f %Sm -t %Y-%m-%d "$f");
#unix:
#date=$(date +%F -r "$f");
y=${date:0:4};
m=${date:5:2};
new_dir="$y-$m";
mkdir -p "$new_dir";
mv "$f" "$new_dir";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment