Frage

I have two subdomains of a website and in both accounts one folder is there with several sub folders. It's a photo folder. In dirA.xyz.com photo folder consists of several folders and sub folders and in dirB.xyz.com photo folder consists of new photos which are not available in dirA. But the sub folder name in dirA photo folder may be the same as dirB photo folder but the final name of image will be different. So I want to move all files of dirB photo folder to dirA photo folder without deleting the dirA photo folder data.

As the name and folder structure varies and data is in millions how to move them and merge so that all data remains?

I've tried using zip. I zipped the photo folder of dirB, moved it to dirA and tried to unzip it but it's not going in dirA photo folder, it's going in dirB photo folder. I've tried changing the owner of dirB photo folder to dirA owner but it also did not work. The only thing that is working is the move command so how can I achieve this with mv?

 mv /home/xyz/public_html/photo/ABC/Something/something/xyz.jpg  /home/ABCDE/public_html/photo/ABC/Something/something/xyz.jpg 

All files are jpeg or png.

War es hilfreich?

Lösung

Sounds like you need rsync, with the merge option, not overwrite. If you are using any decent and recent version of linux, you should have rsync installed by default.

source: /home/xyz/public_html/photo/ABC/Something/something/xyz.jpg
target: /home/ABCDE/public_html/photo/ABC/Something/something/xyz.jpg

rsync -avibu --ignore-existing /home/xyz/public_html/photo/ /home/ABCDE/public_html/photo

On this command I selected the top level directory randomly. You may want to modify according to your needs. Also pay attention to the trailing "/" on both source and destination. Otherwise, placement of files might be a level of directory off.

-b makes rsync backup files that exist in both folders, appending ~ to the old file. You can change the ~ suffix with --suffix string_of_your_choice -u makes rsync transfer skip files which are newer in destination than those in source

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top