Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have several symlinks to other files in a directory. I want to convert these links into independent files.

Is there a command that does this?

share|improve this question
are they hard or soft (symbolic) links? –  swatso33 May 4 '12 at 17:11
They're soft links - editing the question. –  Utkarsh Sinha May 4 '12 at 17:16
I'm interested to know how to do this for hard links. –  Craig McQueen Oct 19 '12 at 2:16
add comment

3 Answers

up vote 8 down vote accepted
cp --remove-destination "$(readlink <symlink>)" <symlink>
share|improve this answer
That felt good! –  Utkarsh Sinha May 4 '12 at 17:35
add comment

While Ignacio's is a good reply, I wanted to automate the process for every file that is a symlink in the current directory and subdirectories.

This does the trick:

find . -type l -exec cp \"{}\" \"{}.tmp$$\" \; -exec mv \"{}.tmp$$\" \"{}\" \;

Hope this helps!

share|improve this answer
add comment

The first way that comes to my mind would be to copy all of the links to new files then delete all of the links.

cp <link> <link>.new
rm <link>

Hopefully the files have some sort of common naming structure so you can use wildcarding and only run the commands once otherwise you might want to write a simple shell script

share|improve this answer
That's what I've been doing till now. I was hoping unix would have some command that does this automatically. –  Utkarsh Sinha May 4 '12 at 17:21
add comment

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.