kc9udx OK, I think I can tell you what happened:
qemu$ uname -a
NetBSD qemu.local 10.1 NetBSD 10.1 (GENERIC) #0: Mon Dec 16 13:08:11 UTC 2024 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64
qemu$ cd /tmp
qemu$ ls -l /etc/motd
-rw-rw-r-- 1 root wheel 76 Dec 20 08:08 /etc/motd
qemu$ ln -sv ~ home
home -> /home/rvp
qemu$ ls -A /tmp/home
.cshrc .login .logout .profile .shrc
qemu$ cp /etc/localtime home # regular copy
qemu$ ls -A /tmp/home
.cshrc .login .logout .profile .shrc localtime
qemu$ cp -a /etc/motd home # "preserving" copy
qemu$ ls -l home # boom! old file's gone
-rw-rw-r-- 1 rvp wheel 76 Dec 20 08:08 home
qemu$ ls -A ~
.cshrc .login .logout .profile .shrc localtime
qemu$
Your /root
must've been a symlink and you used cp -a
to copy the file.
Regular cp
would've worked, as you can see, but, cp -a
overwrites the destination rather than following the symlink to the actual directory.
I would've said this was a bug (both GNU cp
and FreeBSD's cp
, work as you would expect it to), except, this seems to be a deliberate behaviour change on NetBSD. See the commit message here.
I thought the [ -H | -L | -P ]
flags only applied to the source args--like it says in the GNU cp
man-page--but, this hasn't been the case on NetBSD since 2006.
Feel free to file a PR, or discuss on tech-userlevel@
. I can't find the discussion for this because the HTTP tech-userlevel
list archive only goes back to ~2008.
Maybe NetBSD's cp
should have a -T
flag, like GNU's, for explicitly overwriting files?
kc9udx I'm surprised I specified /root
rather than /root/
which I normally do. But I can't recall a time in sh
where this was a problem.
And, this is why I always, always automatically tack-on a /.
to the destination arg. if I mean it to be a directory:
$ cp -a script /root/.