1

I'm trying to build a scrip that compare a file inside different 2 dir,then copy them from dir1 to dir2 is it's not exists in the dir2, or overwrite it if its already existed.

I know that i can use diff dir1 dir2 but then how do copy the result over to dir2. because diff command give me result like only in dir1: file1.txt, from my understand that isn't a file itself(right?)

For the overwrite part, i decide to use [ -ot ] command, but again, from my understand the [ -ot ] only can compare with file but not dir?

2

rsync works locally and does tests on both file timestamps and file sizes.

rsync --archive /path/to/source/ /path/to/destination/

You may also use rsync on individual files.

  • -u is the right option for timestamps comparison ? – Prin Puyakul Sep 28 '17 at 8:41
  • @PrinPuyakul -u will skip files that are newer on the destination end. Without it, rsync will transfer all files whose timestamps (or sizes) are different. – Kusalananda Sep 28 '17 at 8:45
  • I see -a, --archive is what i'm looking for, but I just wonder how can I printout the result from rsync after it successfully execute (like a file name) @Kusalananda – Prin Puyakul Sep 28 '17 at 13:52
  • @PrinPuyakul You may use -v or --verbose to see what it's doing, and --progress to see it work on bigger files. --stats will give you a summary at the end. – Kusalananda Sep 28 '17 at 13:53
  • I did try --archive, but it will copy everything over to a new dir every tho the file has an older timestamp, what did i do wrong ?_?. from what I understand it NOT suppose to copy older timestamp file over the new one right? – Prin Puyakul Sep 29 '17 at 6:52
1

Why not cp?

\cp -f /path/to/dir1/* /path/to/dir2/
  • Thanks, I will try bouth cp and rsync =D – Prin Puyakul Sep 28 '17 at 8:42

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.