Date: Thu, 1 Oct 2020 13:41:13 +0200 From: Polytropon <freebsd@edvax.de> To: freebsd-questions@freebsd.org Subject: Re: Preserving target file's creation date Message-ID: <20201001134113.13ff6d86.freebsd@edvax.de> In-Reply-To: <20201001072728.000004b6@seibercom.net> References: <202010010424.0914OZ9Y029194@sdf.org> <20201001072728.000004b6@seibercom.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 1 Oct 2020 07:27:28 -0400, Jerry wrote: > On Wed, 30 Sep 2020 23:24:35 -0500, Scott Bennett via freebsd-questions > commented: > > On Tue, 29 Sep 2020 13:40:51 +0200 Polytropon <freebsd@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? > > > I found that 'touch -r <source file> <target file>' works. It involves > slightly more work than I had intended, but it gets the job done. According to "man 1 touch", this does not change creation time: -r Use the access and modifications times from the specified file instead of the current time of day. It reads the access and modification timestamp from another file and applies those. Your initial question was about creation time, and that one will be written when the corresponding inode is being created, so the command mentioned above does _not_ affect creation date (while the "redirection trick" does). So if you want to keep all three timestamps identical, you'll have to combine both tasks. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20201001134113.13ff6d86.freebsd>