Set the creation and modification date of a file in OS X using the terminal

By Michael Argentini
Managing Partner, Technology and Design

Sometimes you have to change the creation or modification date of a file, for example, when you edit old images in your personal photo library, the date will change to the current one. And that can cause the edited photos to show up in your photo library as newer items.

You can use the OS X developer tool SetFile on the command line to change a file's creation or modification date, but you must first install the developer tools (Xcode) from the OS X installation media, or by download from the Mac App Store. SetFile can be found in the /usr/bin/ directory in Mac OS X 10.5 and later.

Below is the format of the command call using Terminal.

sudo cd /Developer/usr/bin/
./SetFile -d '10/29/2011 12:00:00 PM' /path/nameoffile.txt

One trick you can use to add the filename to the command is to enter everything through the date, and then drag-and-drop the file onto the Terminal window and it will append the path and filename to the command line.

You can use another program calledGetFileInfoto obtain the modification date.

sudo cd /Developer/usr/bin/
./GetFileInfo /path/nameoffile.txt

Article last updated on 4/21/2018