I want to remove the symlink and instead insert the file it links to, if possible all with one command so I can have it as an "External Tool" in phpStorm.

cp --remove-destination "$(readlink <symlink>)" <symlink>

Source: https://unix.stackexchange.com/a/35027

  • Thanks I tried this and it didn't work but it turns out that it was because the links where copied and didn't point to the right place anymore. But I was confused and thought it was something with bash – OZZIE Nov 1 '14 at 13:49
  • How do I get this to work for all symlinks in a directory? Find complains about illegal option -t whenever I put it in a loop. – cjm Jan 16 '17 at 18:22
  • @cjm This should work fine with find. Are you missing the path as an argument to find? What's your exact find command? – grg Jan 16 '17 at 18:25
  • @grgarside I was missing the path as my find argument. Now my problem is that cp is getting whiny about illegal option -- - instead of recognizing --remove-destination as a valid option. Command is for f in (find . -type l); cp --remove-destination "(readlink $f)" $f;end;; shell is fish. It complains about the illegal option whether or not the (readlink $f) is quoted or not. – cjm Jan 16 '17 at 18:33
  • @cjm You're missing a ‘$’ before the open bracket before readlink (should be "$(readlink). Also why are you using the shell to do the loop? find . -type l -exec cp --remove-destination "$(readlink {})" {} \; – grg Jan 16 '17 at 18:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .