Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 11 down vote accepted
cp --remove-destination "$(readlink <symlink>)" <symlink>
share|improve this answer
error "-bash: syntax error near unexpected token `newline'" when executed from a debian environment. – Goby Sep 24 at 23:53
perl -e '`cp $_ FOO;rm $_;mv FOO $_` for @ARGV' symlink1 symlink2
share|improve this answer
Overly complicated way of doing it, plus it will nuke file FOO, if it should happen to exist. – Joe Sewell Mar 23 at 15:17
@joesewell what would you suggest except accepted solution? – mpapec Mar 23 at 20:01
Ignacio's answer is far more efficient, @mpapec. It just seems like overkill to invoke perl to invoke cp. – Joe Sewell Mar 23 at 20:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.