0

Is it possible to set ctime of a file to a desired value. I am working on a restore script and I need to set the ctime of the file to a previous timestamp after restoring the file.

I tried touch function, but it only sets the atime and mtime.

Yasitha
  • 2,233
  • 4
  • 24
  • 36

2 Answers2

2

You cannot change the ctime by ordinary means. This is by design:

The ctime is always updated to the current when you change any of the file's metadata, and there is no way to impose a different ctime.

To change the ctime of a file, you can:

  • Set the system time to the ctime you want to impose, then touch the file, then reset the system time.
Shashank Shah
  • 2,077
  • 4
  • 22
  • 46
1

ctime is the inode or file change time. The ctime gets updated when the file attributes are changed, like changing the owner, changing the permission or moving the file to an other filesystem but will also be updated when you modify a file.

So you need to perform any of these modifications to a file to change the ctime.

pumbo
  • 3,646
  • 2
  • 25
  • 27
  • When I do these modification to the file ctime change to the current time. That is not I want. Is it possible to set the file's ctime to some previous timestamp value? – Yasitha Mar 14 '16 at 09:25