Read more

Change the timestamp of a file in Ruby

Arne Hartherz
June 30, 2011Software engineer at makandra GmbH

This is somewhat similar to the touch command of Linux:

FileUtils.touch 'example.txt', :mtime => Time.now - 2.hours
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

If you omit the :mtime the modification timestamp will be set to the current time:

FileUtils.touch 'example.txt'

You may also pass an array of filenames:

FileUtils.touch %w[ foo bar baz ], :mtime => Time.now - 2.hours

Non-existent files will be created.

Posted by Arne Hartherz to makandra dev (2011-06-30 15:23)