Replace symlink with actual files

I had a use case where I want to replace existing symlinks with actual files.

cp --remove-destination `readlink filename` filename

Here filename is an existing symlink. With above command the symlink gets removed and gets replaced with actual file.

How this works?

We are using readlink which according to its manpage entry, reads contents of the symlinked file and puts into buffer.

And then cp --remove-destination removes the symlink before creating the same file with the actual contents of the file.