cp overwrites symlinks

wbeinhart at gmx-topmail.de wbeinhart at gmx-topmail.de
Thu Jan 31 09:10:27 UTC 2013


Hi all,

I just found that cp behaves differently compared to native cp if the dst file is a symlink.
In that case the symlink is replaced by by the src file.
Is this intended behaviour?

8<---
# touch foo
# ln -sf foo bar
# echo hello >hello
# ls -l
lrwxrwxrwx    1 root     root             3 Jan 31 09:53 bar -> foo
-rw-r--r--    1 root     root             0 Jan 31 09:53 foo
-rw-r--r--    1 root     root             6 Jan 31 09:53 hello
# cp hello bar
# ls -l
-rw-r--r--    1 root     root             6 Jan 31 09:53 bar
-rw-r--r--    1 root     root             0 Jan 31 09:53 foo
-rw-r--r--    1 root     root             6 Jan 31 09:53 hello
# busybox
BusyBox v1.20.2 (2012-12-24 14:03:26 CET) multi-call binary.
.....
8<---

On a Debian machine the result looks like that:
8<---
root at debian:/tmp/test# ls -l
insgesamt 8
lrwxrwxrwx 1 root root 3 31. Jan 09:44 bar -> foo
-rw-r--r-- 1 root root 6 31. Jan 09:44 foo
-rw-r--r-- 1 root root 6 31. Jan 09:44 hello

8<---

Best regards,
Werner


More information about the busybox mailing list