0

I have an old copy of the remote folder (FD) user@IP:/folder1/folder2/folder3/FD/ which has subfolders fol1, fol2, ...,

user@IP:/folder1/folder2/folder3/FD/
                                   |__fol1
                                   |__fol2
                                   |__ ... 

that contain many files. My local folder has the same name and the same subfolders

/localfd1/localfd2/FD/
                     |__fol1
                     |__fol2
                     |__ ...  

How can I copy from the remote subfolders only the newer files at my local subfolders? scp would copy the entire folders but i only want the new files.

More analyticaly: The OLD COPY of the remote folder that I have, has the structure:

/localfd1/localfd2/FD/
                     |__fol1
                          |_old file1
                          |_old file2
                          |_old file3 
                     |__fol2
                          |_old file4
                          |_old file5

the NEW_REMOTE folder NOW has the form:

 user@IP:/folder1/folder2/folder3/FD/
                                    |__fol1
                                         |_old file3 
                                         |_new file_a
                                         |_new file_b  
                                    |__fol2
                                         |_old file5 
                                         |_new file_c 

(some files in the remote folder was deleted in order to save space + new files are added).

I want to copy from the NEW_REMOTE folders (fol1 and fol2) only the NEW files at my local folder. So my new local folder will have the form:

/localfd1/localfd2/FD/
                     |__fol1
                          |_old file1
                          |_old file2
                          |_old file3 
                          |_new file_a
                          |_new file_b 
                     |__fol2
                          |_old file4
                          |_old file5
                          |_new file_c 
4
  • I don't fully understand this phrase, "How can I copy from the remote subfolders only the newer files at my local subfolders" - can you give examples, i.e. files in both locations, which are newer or older and which ones you want to copy and in which direction. Apr 25 '16 at 12:02
  • @EightBitTon I edited my question for you adding the section "More analyticaly: ..." thnx for yr time and interest Apr 25 '16 at 12:32
  • @phaethon100 : my answer was not helpful to your question ?
    – Rahul
    Apr 25 '16 at 12:35
  • @ arzyfex , it worked like a charm! thank you. U need to be careful though adding "/" at the end of the folders Apr 25 '16 at 13:36
1

You can use

rsync -avh --update user@IP:/folder1/folder2/folder3/FD/ /localfd1/localfd2/FD/ 
from man rsync :

This forces rsync to skip any files which exist on the destination and have a modified time that is newer than the source file. (If an existing destination file has a modification time equal to the source file’s, it will be updated if the sizes are different.)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.