Shriramana Sharma wrote:
What is surprising here is that while I expected the cp operation to replace the link with the text file, it replaced the *target of the link*. Is this expected behaviour? In Konqueror, if I try to copy a regular file to a directory containing a symbolic link with the same name as the file, it asks me if I want to overwrite and if I say yes it overwrites the link, not the target of the link.
The way 'cp' works is that it opens the target file for writing, and the semantics of a symlink is that it is totally transparent to programs. So when cp opens the symlink for writing, it is in fact opening the file the symlink is pointing to. This is correct behaviour from cp Konqueror deletes the target file before it starts the copy, that's why it "overwrites" the symlink and not the other file. You can get the same behaviour from cp if you add the --remove-destination parameter