1760061 Members
4206 Online
108889 Solutions
New Discussion юеВ

Change DateTimeStamp

 
intp
Frequent Advisor

Change DateTimeStamp

Hi,

1) I want to modify a shell script (or any file type ) in Unix. But after making modifications and saving , it should preserve the actual date and not the date when i modified it ...is it possible?

OR
2) If there are no options to preserve timestamp while saving..Let me modify the file and save it in current date. Later , is it possible to change the datetime stamp on that particular file to some earlier date?

Thanks
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor

Re: Change DateTimeStamp

Hi:

First, UNIX does not matain a "creation" timestamp. A modification timestamp, a lastaccess timestamp and a timestsmp that reflects the last change in the file's inode information exist, but no others.

That said, you can alter the modification and/or lastaccess timestamps to anything you choose with 'touch'.

For example to change the last modification time of 'myfile' to yesterday (April 29) at 0001, do:

# touch -mt 04290001 myfile

...or:

To set the timestamp's of 'myfile' equal to 'yourfile' do:

# touch -am -r yourfile myfile

Now, beware that resetting a file's modification time may affect increamental backup runs and remote file distriubtion utilities, both of which use a file's modification timestamp for tracking.

Read the manpages for 'touch(1)' and for 'rdist(1)' for more information.

Regards!

...JRF...
Matti_Kurkela
Honored Contributor

Re: Change DateTimeStamp

See the man page of the "touch" command.
http://docs.hp.com/en/B2355-60127/touch.1.html

Looks like your option 2) is doable with it, at least with HP-UX 11.11 and above.

Your option 1) would be possible only if the editor you use would explicitly re-set the timestamp(s) back to the original value after saving the modified file. Some editors might have such an option, but certainly not all of them.

Note that there are three timestamps associated with each file: the access time (atime), time of last modification of file contents (mtime) and time of last change of file attributes (ctime) like name, ownership, protection and mtime.

Only atime and mtime are changeable by a normal user, and those can be set to a non-current value only if the user actually owns the file.

There is apparently no way to change the ctime to any other value than the present moment. This is to make forgeries more difficult in a multi-user environment.

Of course, anything is possible if you are root and can access the disk directly, bypassing the filesystem.
MK
Hein van den Heuvel
Honored Contributor

Re: Change DateTimeStamp


WHY would you want to engage in such confusing practice?

Even when making say a benign change in the comments to a program source and you think it wise to fool the make utility in thinking the tree is still up to date it still seems bad practice. It's bound to bite you or your succesor when and where it hurts eventually.

fwiw,
Hein.
intp
Frequent Advisor

Re: Change DateTimeStamp

Thanks to All.

Actually we deal with lots of Manual file moves/copies. Sometimes it happens we make mistakes while copying file from one location to other. In such cases , file timestamp changes and its hard to keep track of when did the file really land in our system (from other sources). We usually use
mv , cp -p to preserve timestamps...sometime by mistake we just use cp and loose the timestamp..

so just to bring it back to original timestamp...we need to know how to change the timestamp.

Hope i made myself clear.

Thanks again.
Patrick Wallek
Honored Contributor

Re: Change DateTimeStamp

As said above, you can use the 'touch' command to modify the timestamp, forwards or backwards, of a file.

Have a look at the 'touch' man page for more information.
Hein van den Heuvel
Honored Contributor

Re: Change DateTimeStamp

"Sometimes it happens we make mistakes while copying file from one location to other."

Thanks for that explanation.

I like it much better than the original question.

Some (linux) versions of 'touch' actually have an easy provision for this: -r ref_file (as JRF already pointed out)


Btw.. you seem to frequent the forum a bit. Please read up on some guidelines such as: http://forums1.itrc.hp.com/service/forums/helptips.do?#28
This will allow others to see whether the question received a useful answer or not. And it will show you how to 'close' a topic when it is no longer interesting for you.

Regards,
Hein.