0

I’m attempting to copy a symlink of a file in one directory to another directory.
I need the copy to be a symlink, not a hard link or a broken symlink.

cp -A and cp -P generated broken (flashing) symlinks as indicated by file -b <copied_symlink_file_name>.
cp and cp -R create hard links.
How would I create a copy of the symlink without resorting to ln -s and creating a new symlink from the original file (therefore requiring knowledge of its inode)?

Thanks for your help.

8
  • 1
    cp -P will work as long as the original symlink created is a absolute symlink to the source rather than a relative one. Commented Apr 5, 2024 at 11:41
  • 2
    You don't need to know the inode if you use ln -s: ln -s destination $(realpath source-file). Commented Apr 5, 2024 at 12:53
  • 1
    @OliverKnodel Right idea, but other way 'round: ln -s $(realpath source) destination Commented Apr 5, 2024 at 16:35
  • @OliverKnodel, I agree. I misspoke. I was intending to ask about a solution if I don’t know the original path. Commented Apr 6, 2024 at 13:18
  • @GMaster, thanks. That makes sense. Is there a way to automatically determine the full real path to the source file from a relative symlink? Commented Apr 7, 2024 at 13:08

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.