How to replace a symbolic link with a copy of a file it links to?

8,972
cp --remove-destination "$(readlink <symlink>)" <symlink>
Share:
8,972

Related videos on Youtube

Ivan
Author by

Ivan

Currently I live in Prague, CZ, use Arch Linux on my Toshiba L10 (Centrino "Dothan" 1.6 Mhz) laptop and code (am beginning, actually) Scala 2.8 with NetBeans 6.9. I like Scala very much (finally, the language I really like) and wouldn't mind to get a jr. Scala developer position.

Updated on September 18, 2022

Comments

  • Ivan
    Ivan almost 2 years

    Having a (single, no batch filesystem processing needed) symlink, what a command line to use to replace it with a copy of the file it links to?

  • Lin Song Yang
    Lin Song Yang almost 9 years
    error "-bash: syntax error near unexpected token `newline'" when executed from a debian environment.
  • Stéphane Chazelas
    Stéphane Chazelas almost 7 years
    If <symlink> is a symlink to a relative path, that only works if the <symlink> is in the current directory. You may want to use readlink -f. Or if using zsh: cp --remove-destination path/to/symlink(:A) path/to/symlink