简体   繁体   中英

How do i copy a folder having symbolic link to another directory

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

  1. you zip the entire folder in the original location.
  2. then sudo copy this zip file to the machine where jenkins is running
  3. stop jenkins
  4. sudo unzip -o jenkinslts.zip
  5. now restart jenkins

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM