I have files named "clip-2016-03-01 10;01;14.mp4" and would like to make filename to creation date of file.

Found this thread read creation date from file name and change - batch

for f in *; do
t=$(echo $f | sed -E 's/([A-z]*-)|([ ,;])|(\..*)//g' | sed -E 's/(.*)(..)/\1.\2/')
touch -t $t "$f"


But I'm not that used to using terminal.

1. Where do I put the search string to the folder containing the files in terminal?

  1. Also found another thread suggesting that touch command won't work and that I should use SetFile -d command. https://superuser.com/questions/492342/how-can-i-batch-shift-the-creation-date-of-files-on-os-x-10-6-8

2 Answers 2


This will operate on all files in the Current Directory. You could cd ~/MyDirectory, either in the script or in Terminal before running it. Another option is to change the * in for f in *; do to ~/MyDirectory/*

This won't actually give you the creation time, because it isn't stored by Unix. Ctime actually records the time of the last status change (which may or may not be creation time).

OS X seems to store other data in extended attributes, but this is not what the script does.


Here is the tip I like for getting people used to the finder and terminal.

Have one finder window open showing the folder and have a terminal window below it.

Type - c, d, space and then drag the folder into the window of the terminal.


The POSIX path of the finder folder will then be pasted into the window. Press enter/return and you will now be in the directory you need.

That lets the script you mentioned run. Also, please be sure you have a good backup and know how to use it. Terminal commands with * can sometimes match more files than you expected. Something like rm -rf is not "read mail, really fast" and can lay waste to priceless pictures and things you have no trash can to undo the remove. Touch is safer in that it will just create lots of new files and chance the access times of other files - but it's best to learn caution and have a backup when you start automating file operations. Good Luck and feel free to ask more automation questions here as you grow more confident or run into issues.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .