how is cp -f different from cp --remove-destination?

There's a distinction between the two (emphasis mine):

if an existing destination file cannot be opened, remove it and try again
remove each existing destination file before attempting to open it

In the first case, if the file can be opened, cp will attempt to replace only the contents. cp is not going to remove the file unnecessarily. This will retain the permissions and ownerships of the original file unless you specify that they're to be copied too.

The second case is useful when the contents can't be read (such as dangling symlinks).


and: in case the destination file has multiple links (hardlinks), --remove-destination will not destroy the content of the other links. Instead just the link of the destination is removed (now we know, why "remove" is called "unlink" in deeper system functions) and a new file with a new inode is created.

Tags:

Linux

Cp