# Stamping my own timestamp

**URL:** <https://www.ruby-forum.com/t/stamping-my-own-timestamp/109530>\
**Category:** Ruby\
**Created:** [July 16, 2007, 2:32pm UTC](https://www.ruby-forum.com/t/stamping-my-own-timestamp/109530 "2007-07-16T14:32:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [July 16, 2007, 2:32pm UTC](https://www.ruby-forum.com/t/stamping-my-own-timestamp/109530/1 "2007-07-16T14:32:35Z")

</div>

Is there a way to “touch” a file with a time stamp of my own choosing,  
in other words, not the “now” time? I’ve got a bunch of files that have  
been inadvertently “touched” time-wise, and I need them to have truer  
time stamps, from a month or so ago.

Thanks,  
Peter

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [July 16, 2007, 2:58pm UTC](https://www.ruby-forum.com/t/stamping-my-own-timestamp/109530/2 "2007-07-16T14:58:18Z")

</div>

2007/7/16, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Is there a way to “touch” a file with a time stamp of my own choosing,  
> in other words, not the “now” time? I’ve got a bunch of files that have  
> been inadvertently “touched” time-wise, and I need them to have truer  
> time stamps, from a month or so ago.

[http://www.ruby-doc.org/core/classes/FileUtils.html#M004385](http://www.ruby-doc.org/core/classes/FileUtils.html#M004385)

e.g. FileUtils.touch(“foo”, :mtime =\> Time.now)

robert

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [July 16, 2007, 3:25pm UTC](https://www.ruby-forum.com/t/stamping-my-own-timestamp/109530/3 "2007-07-16T15:25:56Z")

</div>

Robert K. wrote:

> 2007/7/16, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > Is there a way to “touch” a file with a time stamp of my own choosing,  
> > in other words, not the “now” time? I’ve got a bunch of files that have  
> > been inadvertently “touched” time-wise, and I need them to have truer  
> > time stamps, from a month or so ago.
> 
> [http://www.ruby-doc.org/core/classes/FileUtils.html#M004385](http://www.ruby-doc.org/core/classes/FileUtils.html#M004385)
> 
> e.g. FileUtils.touch(“foo”, :mtime =\> Time.now)
> 
> robert

Thanks. But, this is what I get when I try that. Doesn’t the “Time.now”  
give it the time of right now?

irb(main):003:0\> FileUtils.touch(file, :mtime =\> Time.now)  
ArgumentError: no such option: mtime  
from c:/ruby/lib/ruby/1.8/FileUtils.rb:1424:in  
`fu_check_options' from c:/ruby/lib/ruby/1.8/FileUtils.rb:1009:in `touch’  
from (irb):3

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [July 16, 2007, 3:56pm UTC](https://www.ruby-forum.com/t/stamping-my-own-timestamp/109530/4 "2007-07-16T15:56:24Z")

</div>

2007/7/16, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > 
> 
> ```
> from (irb):3
> 
> ```

Works for me:

irb(main):003:0\> FileUtils.touch “f”, :mtime =\> Time.now  
=\> [“f”]  
irb(main):004:0\> RUBY\_VERSION  
=\> “1.8.6”  
irb(main):005:0\> File.mtime “f”  
=\> Mon Jul 16 15:52:06 +0200 2007

Alternatively you can try to use File.utime().

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [July 16, 2007, 4:05pm UTC](https://www.ruby-forum.com/t/stamping-my-own-timestamp/109530/5 "2007-07-16T16:05:20Z")

</div>

Robert K. wrote:

> 2007/7/16, Peter B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > > 
> > 
> > ```
> > from (irb):3
> > 
> > ```
> 
> Works for me:
> 
> irb(main):003:0\> FileUtils.touch “f”, :mtime =\> Time.now  
> =\> [“f”]  
> irb(main):004:0\> RUBY\_VERSION  
> =\> “1.8.6”  
> irb(main):005:0\> File.mtime “f”  
> =\> Mon Jul 16 15:52:06 +0200 2007
> 
> Alternatively you can try to use File.utime().
> 
> Kind regards
> 
> robert

Thanks, Robert. That particular thing just doesn’t work for me, but, I’m  
intrigued by File.utime. I read about it a bit and I think it might do  
the trick. Thanks a lot!
