# Changing Creation Date of a file

Could you please let me know how I can change the creation date of a file in Lion. I realise there is the touch-t command but that does not work in Lion. A couple of people have mentioned another way, but I think they've written the solution in "coder" language rather than layman language - would someone be able to answer it in a way a layman can execute?

• The "coder" explanation other people have written about is probably a reference to "touch". You'd have to open a Terminal, navigate to the folder where the file is then use the touch command to modify the fie's creation date. – Derek Knight Aug 20 '13 at 22:44
• FWIW You are on the right lines with "touch-t", but there is a space between the h and the -. It's "touch -t" – Derek Knight Aug 20 '13 at 22:55

touch -t normally only changes the modification and access times. It only changes the creation time if the target time is before the original creation time.

touch -t 199912312359 file.txt
touch -t $(date -jf %FT%T 1999-12-31T23:59:59 +%Y%m%d%H%M%S) file.txt  SetFile -d always changes the creation time. SetFile -d '12/31/1999 23:59:59' file.txt SetFile -d "$(GetFileInfo -m test.txt)" file.txt


• -m for changing modification time. – AlikElzin-kilaka Apr 13 '14 at 12:23
• In Yosemite, touch required me to use the format +%Y%m%d%H%M.%S (notice the dot between minutes and seconds) – Calimo Apr 27 '15 at 9:39
• I wrote a function called CpCreationDate in fish: SetFile -d (GetFileInfo -m $argv[1])$argv[2] – Pascal Oct 11 '15 at 13:52

In Mac OS X there appears to be four different timestamps associated with a file. These timestamps are not always updated independently from each other, but one can have some individual control with a bit of care and with use of touch, SetFile, and chown (or chmod). To see this, let's experiment and create a new file from the command prompt #:

# touch a.txt
# stat a.txt
16777218 5969798 -rw-r--r-- 1 username staff 0 0 "May 19 00:11:14 2015" "May 19 00:11:14 2015" "May 19 00:11:14 2015" "May 19 00:11:14 2015" 4096 0 0 a.txt


The first date listed is last access time (atime), the second is last modification time (mtime), the third is last status change (ctime), the fourth is time of file creation (birth, Btime), see man lstat.

To modify access time (atime) to a specified time use:

# touch -a -t201412312359.59 a.txt
# stat a.txt
16777218 5969798 -rw-r--r-- 1 username staff 0 0 "Dec 31 23:59:59 2014" "May 19 00:11:14 2015" "May 19 00:11:46 2015" "May 19 00:11:14 2015" 4096 0 0 a.txt


To modify modification time (mtime) and time of file creation (Btime) to a specified time use:

# touch -m -t201312312359.59 a.txt
# stat a.txt
16777218 5969798 -rw-r--r-- 1 username staff 0 0 "Dec 31 23:59:59 2014" "Dec 31 23:59:59 2013" "May 19 00:12:19 2015" "Dec 31 23:59:59 2013" 4096 0 0 a.txt


Apparently this also automatically updates the time of last status change (ctime) to the current system time!

To modify only the time of creation/birth (Btime) to a given time, use (as proposed by others above):

# SetFile -d "12/31/1999 23:59:59" a.txt
# stat a.txt
16777218 5969798 -rw-r--r-- 1 username staff 0 0 "Dec 31 23:59:59 2014" "Dec 31 23:59:59 2013" "May 19 00:12:19 2015" "Dec 31 23:59:59 1999" 4096 0 0 a.txt


To modify only the time of last status change (ctime) to the current system time use for example:

# chown username a.txt
# stat a.txt
16777218 5969798 -rw-r--r-- 1 username staff 0 0 "Dec 31 23:59:59 2014" "Dec 31 23:59:59 2013" "May 19 00:13:45 2015" "Dec 31 23:59:59 1999" 4096 0 0 a.txt


where username is the owner of the file (as reported by stat or ls -l). This doesn't change the ownership of the file, but accesses the file's inode and records this as a time of last status change. Unfortunately, it is not possible to specify the time explicitly here other than by changing the computer's time...

In summary, to be able to change the four timestamps independently, one may use (in this order for the last 3):

1. touch -a -tCCYYMMDDHH.SS <file>
2. touch -m -tCCYYMMDDHH.SS <file>
3. SetFile -d "MM/DD/CCYY HH:MM:SS" <file>
4. [set system date] chown username <file> [revert to normal system date]

(Of course, resetting the system date may not be a risk-free operation, you've been warned.)

• +1 Thank you for this super detailed answer. This solved all my woes. – Govind Rai Nov 8 '16 at 23:14

The command-line touch command works in Lion, but you need a little background on how to use it.

Firstly, you need to type it in, it's not a utility that operates graphically in a window. The place you type it in is an app called Terminal. You can find this in your Utilities folder, or use Spotlight search to find it.

Once you start it, you get a command line window where you can type in commands. Just because you are typing doesn't mean it has anything to do with coding, but to someone new to "old fashioned" OS commands it can look a little intimidating.

So, the command is called touch, and after the command you can pass various parameters, the only required one being the filename. Typing the following will set the last modified date of the file to the current time:

touch filename


Of course, you may need to find the file first, which could require further commands to get to it. the cd or Change Directory command helps here:

cd ~/Desktop/files/PDFs
touch filename


Or, you can simply add the full path to the file as part of the command:

touch ~/Desktop/files/PDFs/filename


More advanced usage of the touch command allows you to specify the time you want to set, rather than using the time at execution, set access instead of modification times etc. This is what parameters like -t and others do. Some set the time to be the time of another file, some set it to go back, or forward in time by X amount, (see here for more details), eg:

touch -d '1 May 2005 10:22' file8


The following is from this page which is also useful reference, and a great example with some tips for those who are uncomfortable with file locations on the command line

Note that this will change both the date modified and date created attributes only if your file was created after the date you enter. This is because a file cannot be modified before it has been created. If created before the date you set, only the modified date will be changed.

How to change the date created attribute of a file?

1. Open up the Terminal application (/Applications/Utilities/Terminal.app) or if you prefer use iTerm.

2. Type this into Terminal (without hitting enter/return) inserting the date in the format of YYYYMMDDhhmm:

touch -t 201212211111

3. Open a Finder window and locate the file you wish to modify and drag and drop it into the Terminal window, it will then insert the file location using command line terminology. Here’s an example of what should be typed into the Terminal at this point:

touch -t 201212211111 /Volumes/Mac\ HD/Pictures/somefile.jpg


201212211111 in the example above represent “December 21, 2012 11:11 AM

• But touch modifies the modified date, not the creation date of the file. – Daniel Aug 21 '13 at 14:35
• It can do both. Depends on the parameters. – stuffe Aug 21 '13 at 14:39
• Using touch with the parameters you gave above changed the modification but not creation dates for my test file. – Daniel Aug 21 '13 at 14:50
• @Daniel You probablly got your answer, but for completeness sakes touch does modify the creation date depending on the arguments. If you supply a modification date that is before the file's creation date, the creation date will automatically change to the new modification date value, as a file cannot be modified before it is created. – Govind Rai Nov 9 '16 at 7:25
• I just tried this on Sierra and touch definitely does not change the creation date. I was able to change access and modified dates to a "date in the past", but it did not modify creation date. Check the man page for touch, it does not mention creation date. File system : Mac OS Extended (Journaled, Encrypted). Using SetFile -d "$(GetFileInfo -m test.txt)" file.txt worked perfectly. – Jonathan Cross Jan 16 '18 at 16:48 Greats hints here, in particular the last one (from Lauri Ranta, answered Aug 21 at 15:21). Perfekt! I now use a simple Automator Workflow to batch change multiple files: 1. Get Selected Finder Items 2. Run Shell Script, "Pass input: as arguments" The shell script is: for f in "$@"
do
SetFile -d "$(GetFileInfo -m "$f")" "\$f"
done


This works like a charm.

The easiest way I found was to create a new folder, copy all the sub-folders of the greyed out folder into the new folder, and voila, the new folder is not greyed out. You can even do this in the finder.