Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

File#ctime

() -> ::Time
ctime → time

On Windows, returns the birthtime for the entry in self.

On other systems, returns a new Time object containing the time of the most recent metadata change to the entry in self; see File System Timestamps:

Example
# A directory.
dirpath = '/tmp/dir'
Dir.mkdir(dirpath)                     # Establishes directory ctime.
dir = File.new(dirpath) # (Dir does not have method ctime; we use File.)
dir.ctime                              # => 2026-10-05 17:23:49.406452569 -0500
# A file therein.
filepath = File.join(dirpath, 't.tmp') # => "/tmp/dir/t.tmp"
File.write(filepath, 'foo')            # Establishes file ctime.
file = File.new(filepath)
file.ctime                             # => 2026-10-05 17:26:26.467758515 -0500
dir.ctime                              # => 2026-10-05 17:26:26.467758515 -0500
File.write(filepath, 'bar')            # Updates file ctime; not directory ctime.
file.ctime                             # => 2026-10-05 17:28:26.307497599 -0500
dir.ctime                              # => 2026-10-05 17:26:26.467758515 -0500
FileUtils.rm_rf(dirpath)               # Clean up.
See also .ctime #chown #flock #chmod also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0