3

I have made many changes to files in my PHP project and I want to push those changes to our server via FileZilla FTP. Rather than push all of the files, I would like to find only the files that have been modified in the last 14 days and copy those to a /ModifiedFiles folder, preserving the folder structure. This way I can simply drag the contents of the /ModifiedFiles folder into FileZilla and it will overwrite all the necessary files in the appropriate folders.

If I was using Windows, I could run this line of code and it would accomplish what I want:

xcopy RUF_Donation_Web ModifiedFiles /S /V /I /R /D:02-09-2016

How can I accomplish this in my Bash terminal on my Mac (OS X Yosemite)?

1
  • 3
    Can you use rsync instead?
    – terdon
    Feb 23, 2016 at 15:19

2 Answers 2

5

That's a typical job for cpio or pax:

find . -type f -mtime -14 -print0 | pax -0 -rw /ModifiedFiles

You could also use the -l option, to make links instead of copies. It doesn't work properly with the pax command on Debian, but maybe the one on OS/X doesn't have the same problem.

You can do something similar with cpio (an ancestor of pax), but the cpio implementation on OS/X doesn't seem to support a -0/--null option which would allow arbitrary file names. If you know your file names don't contain newline characters, you can still do:

find . -type f -mtime -14 | cpio -dp /ModifiedFiles

Both Debian (GNU) and OS/X versions of cpio also have a -l option to make links instead of copies. (and the one of Debian seems to work properly).

2

What you are trying to implement is build in rsync. You can just rsync -a /source /dest. You can put that in a simple script and then add it as a cron job. If you want to keep logs of what has been copied you can append --log-file=[File] option. You can find more info here: http://linux.die.net/man/1/rsync

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .