I am trying to copy a folder having symbolic links to another directory
Note - The actual files i intend to copy are different but just for the purpose of this question to make it easy to demonstrate issue , i am giving a example
xd003@localhost:~$ ls /data/data/com.termux/files/home/source
1.txt 2.txt 3.txt symlink
xd003@localhost:~$
Here's the source folder which has some files and a symbolic link , and the destination folder is empty
xd003@localhost:~$ cp -R /data/data/com.termux/files/home/source /sdcard/dest
cp: cannot create symbolic link '/sdcard/dest/source/symlink': Operation not permitted
xd003@localhost:~$
I copy the source folder to destination directory but i get an error stating the symlink cannot be copied over , just to confirm i check the destination directory and as expected it didn't copied the symbolic file
xd003@localhost:~$ ls /sdcard/dest/source
1.txt 2.txt 3.txt
xd003@localhost:~$
How do i fix this issue and copy the symbolic link in its original state
Edit - After some googling and one answer suggestion below , i tried using cp -LR command .It didn't gave me any error but it copied the symlink as folder and not in its original state , as you can see below the first line itself shows the symlink in destination is copied as a folder and in source , it indeed is a proper symbolic link
xd003@localhost:~$ ls -la /sdcard/dest/source | grep "\->"
xd003@localhost:~$ ls /sdcard/dest/source
1.txt 2.txt 3.txt symlink
xd003@localhost:~$ ls -la /data/data/com.termux/files/home/source | grep "\->"
lrwxrwxrwx. 1 xd003 xd003 13 Jun 12 12:40 symlink -> /sdcard/data/
xd003@localhost:~$
You need to dereference the links:
cp -L -R files/* location/
-L is used to dereference or --dereference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With