In order to run Code dx on Linux files, I need to replace all links with the actual files. Haven't worked in Linux in years and am getting confused by terminology. Been searching for answers for two days. Is there a simple script for this? I have 25 million lines of code.

Original dir: afile bfile clink_to_cfile_in_another_dir (possible traversing several links)

Desired end result: afile bfile cfile

I have gotten this far, but it doesn't quite work:

find . -type l -exec "echo 'replacing {}'; cp -LR '{}' '{}'.deref rm '{}' \;"
  • I have gotten this far:
    – Linda
    Nov 8 '17 at 1:11

There are several issues

  • The \; needs to be outside the quotes, it is a separate argument to exec
  • You are missing a ; before the final rm command
  • exec will try and run the whole command as one single command.

To run multiple commands like this you can exec a shell and pass your script to it

find . -type l -exec /bin/bash -c "echo 'replacing {}'; cp -LR '{}' '{}.deref' ; rm '{}'" \;

seems to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy