Skip to content

Instantly share code, notes, and snippets.

@markwk
Created April 5, 2019 04:40
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 markwk/5e6ebffb9775cfe6f32cebc660ab5f30 to your computer and use it in GitHub Desktop.
Save markwk/5e6ebffb9775cfe6f32cebc660ab5f30 to your computer and use it in GitHub Desktop.
Bash script to append date of creation to a text file.
#!/bin/bash
cd /Users/markkoester/Desktop/
for f in *.txt ; do
if [ -f "$f" ]
then
filedatetime=$(stat -f '%Sm' -t '%Y%m%d%H%M' "$f")
filename=$(basename -- "$f")
extension="${filename##*.}"
filename="${filename%.*}"
filename="${filename// /_}"
mv "$f" ${filedatetime}_${filename}.${extension}
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment