Skip to content

Instantly share code, notes, and snippets.

@Phlow
Created January 11, 2017 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Phlow/896649b31202cc888f0819b3d266496d to your computer and use it in GitHub Desktop.
Save Phlow/896649b31202cc888f0819b3d266496d to your computer and use it in GitHub Desktop.
When renaming files in terminal, you can use their time stamp. This bash/shell script helps you. It uses `stat` to get the information, formats the time stamp with `date` and renames each file with `mv`.
#
# When renaming files in terminal, you can use their time stamp. This bash/shell script helps you.
#
# One liner: for f in *.jpg; do D=$(date -r $(stat -f %B $f) +%Y-%m-%d-%H-%M-%S); mv -vi "$f" "$D-$f"; done
for datei in *.jpg
do VARIABLE_WITH_FORMATTED_DATE=$(date -r $(stat -f %B $datei) +%Y-%m-%d-%H-%M-%S)
mv -vi "$datei" "$VARIABLE_WITH_FORMATTED_DATE-$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment