How to copy the target file vs the symlink

symlink

I have files with symlinks as shown below :

link_AB91 -> file_12857.xml
link_XY99 -> file_102856.xml
link_EF02 -> file_96843.xml

In my script I reference the link not the actual target file.
However, when I perform the copy I want the actual file copied over.
I am looking for an option and/or command which will allow me to achieve this.

Example :

cp "some_option_here" link_AB91 .

This should copy file file_12857.xml not the link link_AB91
I have tried options -L and -H but they do not help
Note that I do not want the -d or -P option either.

Update : If not option exists, then I will use readlink command but I am hoping there is a quicker way of performing this task

Best Answer

Use readlink /path/to/link to get the real file


cp `readlink /path/to/my/link` /foo/destination

equals


cp $(readlink /path/to/my/link) /foo/destination

Related Topic