Is there any way to rename a file while keeping the original creation / modification/ read time? This is in Solaris.
Thanks in advance.
I don't think you can do that with mv
. However, you can with cp -p
; copy the file to a new name, then delete the original. The -p
flag preserves timestamps.
You will get a new inode though... something you wouldn't with mv
In a variation on the theme suggested by others:
cp -al "$oldname" "$newname"
unlink "$oldname"
should avoid any copying as long as $oldname and $newname are on the same mountpoint (filesystem).
You're in luck.
Solaris (with ZFS) is one of the very few filesystems that actually honour a creation time property for files.
Now on topic: No you cannot preserve all times: the inode will change and the filename changes. This means that the inode ctime will change by (POSIX) definition.
Your last accessed time will also change, unless you're running a noatime mount point (zfs set atime=off).
I don't think there is a way to change that. However, the file creation date time should not be changed at all. I was going to show the commands to show creation times, but unfortunately I don't have a Solaris box handy and I can't seem to find it. I think your best bet is man ls find stat
.
GL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With