How to 'touch' a file to a time other than now?

Rubies:

The only post I can find regarding ‘touch’ sez this:

fn = ‘/usr/aDirectory/aFile’

oops, we don’t have File.touch

File.open(fn, “w”).close unless File.exist?(fn)

As it’s by Matz, I’l take it as authoritative we got no ‘File.touch’.

I don’t want to do the file open close trick. I need to set the time back
to a while ago, and changing the platform time is out of the question; I’m
running on a busy server.

I’l shell to the GNU ‘touch’, but if folks don’t have it they are screwed.

Are there more primitive things I can do to get in ‘touch’?

···


Phlip
http://www.greencheese.org/SonseOne
– It’s a small Web, after all… –

Phlip phlipcpp@yahoo.com writes:

Are there more primitive things I can do to get in ‘touch’?

% ri File.utime
------------------------------------------------------------ File::utime
File.utime( anAccessTime, aModTime [, fileName]+> ) → aFixnum

···
 Changes the access and modification times on a number of files. The
 times must be instances of class Time or integers representing the
 number of seconds since epoch. Returns the number of files
 processed. Not available on all platforms.
    File.utime(0, 0, "testfile")          #=> 1
    File.mtime("testfile")                #=> Wed Dec 31 18:00:00 CST 1969
    File.utime(0, Time.now, "testfile")   #=> 1
    File.mtime("testfile")                #=> Sun Mar 04 23:28:25 CST 2001


eban

touch foo

ls -l foo

-rw-r–r-- 1 root www 0 2002-12-18 00:15 foo

irb

irb(main):001:0> File.utime(Time.now - 600, Time.now - 900, “foo”)
1
irb(main):002:0>

ls -l foo

-rw-r–r-- 1 root www 0 2002-12-18 00:12 foo

– Dossy

···

On 2002.12.18, Phlip phlipcpp@yahoo.com wrote:

Are there more primitive things I can do to get in ‘touch’?


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

WATANABE Hirofumi wrote:

File.utime( anAccessTime, aModTime [, fileName]+> )

Ah, I get it. In the original example someone was using ‘touch’ to make a
zero-length file exist, which the above won’t do. Hence the quote “no
touch”. Thanks.

···


Phlip
greencheese.org
– This machine last rebooted during the Second Millenium –