Why Linux 'cp' command did not copy files from soft link completely?

I have a soft link which linked to a nested image folders (thousand of images)

(DRS) xzhan@4daf823ea86f:~$ ls -l voc12_root
lrwxrwxrwx 1 xzhan aiml 30 Mar 16 15:20 voc12_root -> /mnt/Data/Datasets/voc12_root/

and I want to copy the images in one of its sub-folder:

(DRS) xzhan@4daf823ea86f:~$ cp -r voc12_root/VOCdevkit/VOC2012/ ~/DRS_dataset

The 'cp' command should work fine, but it seems that some images loss during the copy process and I can't troubleshot it. Any one can help me?

(DRS) xzhan@4daf823ea86f:~$ du -b voc12_root/VOCdevkit/VOC2012/
5341193450 voc12_root/VOCdevkit/VOC2012/superpixels
74008 voc12_root/VOCdevkit/VOC2012/ImageSets/Segmentation
2352400 voc12_root/VOCdevkit/VOC2012/ImageSets/Action
29596 voc12_root/VOCdevkit/VOC2012/ImageSets/Layout
7205056 voc12_root/VOCdevkit/VOC2012/ImageSets/Main
9665156 voc12_root/VOCdevkit/VOC2012/ImageSets
18642246 voc12_root/VOCdevkit/VOC2012/Annotations
9322572 voc12_root/VOCdevkit/VOC2012/SegmentationObject
1922590472 voc12_root/VOCdevkit/VOC2012/JPEGImages
9359317 voc12_root/VOCdevkit/VOC2012/SegmentationClass
8110414228 voc12_root/VOCdevkit/VOC2012/
(DRS) xzhan@4daf823ea86f:~$ du -b DRS_dataset/
1922565896 DRS_dataset/JPEGImages
7205056 DRS_dataset/ImageSets/Main
74008 DRS_dataset/ImageSets/Segmentation
2352400 DRS_dataset/ImageSets/Action
29596 DRS_dataset/ImageSets/Layout
9665156 DRS_dataset/ImageSets
1922565896 DRS_dataset/VOC2012/JPEGImages
7205056 DRS_dataset/VOC2012/ImageSets/Main
74008 DRS_dataset/VOC2012/ImageSets/Segmentation
2352400 DRS_dataset/VOC2012/ImageSets/Action
29596 DRS_dataset/VOC2012/ImageSets/Layout
9665156 DRS_dataset/VOC2012/ImageSets
5341172970 DRS_dataset/VOC2012/superpixels
9322572 DRS_dataset/VOC2012/SegmentationObject
9359317 DRS_dataset/VOC2012/SegmentationClass
18646342 DRS_dataset/VOC2012/Annotations
8110373268 DRS_dataset/VOC2012
5341172970 DRS_dataset/superpixels
9322572 DRS_dataset/SegmentationObject
9359317 DRS_dataset/SegmentationClass
18646342 DRS_dataset/Annotations
16220746536 DRS_dataset/
1

1 Answer

In order to copy symlinks fully and preserve them as a symlink, you can use the -H flag in addition to -r one. Therefore your command would be as follows:

cp -rH voc12_root/VOCdevkit/VOC2012/ ~/DRS_dataset

If you don't want to preserve the symlink, but make a directory out of it, you can use the -L flag:

cp -rL voc12_root/VOCdevkit/VOC2012/ ~/DRS_dataset

Hope that helps. :)

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like