tags:

views:

285

answers:

3

I would like to be able to change a file's modification date for use in a web application. For the time being I am testing this directly on the command line. Works fine on my mac, but when I do this on a linux server get error.

Command: /bin/touch -m -t 200906041200 /foo/bar/file.whatever

Error: /bin/touch: setting times of `/foo/bar/file.whatever': Operation not permitted

The file in question is 777.

A: 

Are you using noatime? That could explain the issue.

Jean Azzopardi
+1  A: 

Even though the file permissions may be read/write for owner, group and other, I believe you need to actually own the file in order to change the atime for the file in question.

Erik
Not sure if I can accept two answers, but this is also valid answer.
Louis W
+3  A: 

On Linux you must be the file owner (or root) to change the modification time to a time other than the current time. There are some other restrictions as well. man utime for complete details.

mark4o
Ahh crap. Is creation date the same as well?
Louis W
If you mean the ctime, that cannot be changed by anyone to any time other than the current time. (Unless of course you are root, in which case you can edit the inode and make it whatever time you want.)
mark4o
@Louis: UNIX filesystems do not have a concept of "creation time". There's atime = "access time" (self-explanatory), ctime = "inode change time" (link created or removed, permissions modified, etc.), and mtime = "modification time" (data changed).
ephemient