Preserving target file's creation date

Scott Bennett bennett at sdf.org
Thu Oct 1 04:24:31 UTC 2020


     On Tue, 29 Sep 2020 13:40:51 +0200 Polytropon <freebsd at edvax.de>
wrote:

>On Tue, 29 Sep 2020 06:42:18 -0400, Jerry wrote:
>> I am trying to copy/move one file onto another. I need to preserve the
>> creation date of the target file. I see options to preserve the
>> creation date of the source file, but not the target file. Is it
>> possible?
>
>THis is possible - it's important you do not unlink (remove)
>the original file whose creation time you want to preserve.
>I'm not sure if cp does this while overwriting, but you can
>use shell redirection:
>
>	$ cat /path/to/souce/file > /path/to/target/file
>
>Only the modification date will be altered. You can verify
>that using "stat filename".
>
>Note that creation time refers to the inode. Even if you
>re-create a file (remove, then create with the same name),
>you'll probably get a different inode, and therefore a
>different creation time.
>
>If you want to preserve modification and access time, you
>can do so using "cp -p"; to alter them after creation,
>use "touch -m" and "touch -a" respectively.
>
     There exists another way that allows one to set the ctime.  Offhand,
I don't have any idea how to do it, but restore(8) certainly does.  A
"restore -rf /some/backupmadebydump/file" will restore an entire filesystem
with each file's full set of timestamps intact.  Recall that restore(8)
rebuilds the filesystem by engaging the filesystem code, not by writing to
a raw device.
     Any ideas what restore does to accomplish that?


                                  Scott Bennett, Comm. ASMELG, CFIAG
**********************************************************************
* Internet:   bennett at sdf.org   *xor*   bennett at freeshell.org  *
*--------------------------------------------------------------------*
* "A well regulated and disciplined militia, is at all times a good  *
* objection to the introduction of that bane of all free governments *
* -- a standing army."                                               *
*    -- Gov. John Hancock, New York Journal, 28 January 1790         *
**********************************************************************


More information about the freebsd-questions mailing list