How to correct incorrect dates on files & disks?

HandyMac

Registered
The one thing I truly miss from the otherwise unlamented Norton Utilities of the classic Mac era is that it would fix incorrect dates (created, modified) on files, directories, volumes, etc. Such incorrect dates (1904, 1976, etc.) would occur when the computer's internal clock reverted to its default date due to a dead battery, etc. I've had clients who've unwittingly used their computers for months with such dates, creating/modifying hundreds of files with bad dates.

Incorrect dates on files & folders can be corrected one at a time or in batches with a utility such as FileXaminer -- but you have to know which ones are incorrect, and it won't allow correcting dates on a disk.

Does anyone know of a utility for OS X that will scan the disk and correct all the dates like Norton used to do?
 
You can use Unix' command touch to

a) create a new empty file
b) change files date

By default, touch changes file's date to the current date, but you could make it to what
ever you like.

You did not say what makes file's date bad (or you hinted that they are old) or how do
you like to correct them.

But let as assume that you like to change all files creation date that are older than
1.1.2001 10:10 to 1.1.2001 10:10.

1. Start Terminal.app
2. Create a file that contains the correct time:

touch -t 200101011010 /tmp/stamp

(The file is empty, but that is alright, we need only its creation time
3. Change to the directory you like to modify

cd ~/TheWrongDays

4. Change dates of all files that are older than /tmp/stamp to have creation time of /tmp/stamp:

find . -type f -not -newer /tmp/stamp -print0 | xargs -0 touch -r /tmp/stamp

Ok, this might look hard, but is says:

find: Find files that match the expression and do something to them
. : search the files in the current directory and its subdirectories
-type f : Match only normal files (i.e. type "f")
-not : reverse next expression, i.e. match all that do not match it
-newer /tmp/stamp: match all files that are newer than the stamp file
-print0 : print all files (ending with ascii code 0; I don't remember if OS Xs older than 10.5 have this. Try -print instead, but then files with spaces etc cause trouble)
| : read everything previous command prints and give to the next command as input
xargs: read then input and give it to the command as argument (or several arguments)
-0: assume that the input comes from find -print0
touch -r /tmp/stamp: run the touch command with option -r /tmp/stamp and one or several files comming from the find. This changes all the files' creation date/time to be same as /tmp/stamp.

5. Remove the stamp file

rm /tmp/stamp
 
Thanks. As a 20-year Mac user I'm more familiar with ResEdit than with Terminal, but I'll try this sometime. Be nice if someone would make this into a GUI utility.
 
Back
Top