Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change file time (touch)

Tags:

linux

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.

like image 631
Louis W Avatar asked Jun 04 '09 21:06

Louis W


People also ask

How do I change timestamp on touch?

Changing file timestamps to a specific date and time If you have a specific time and date you would like to be used for all the timestamps of a file or directory, touch command will gladly accempt a timestamp template with -t command line option. Template for the timestamp is quite thorough: [[CC]YY]MMDDhhmm[.

How do I change the timestamp on a file?

If you ever want to quickly update the Modified time stamp of a file to the current day and time, right-click that file, select Properties, select the TimeStamps tab, and then click the Touch button. That will instantly change the Last modified entry to the current day and time.


2 Answers

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.

like image 131
mark4o Avatar answered Sep 28 '22 10:09

mark4o


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.

like image 32
Erik Avatar answered Sep 28 '22 09:09

Erik