TransWikia.com

Bash script for copying only modified files

Ask Ubuntu Asked by indr0 on February 4, 2021

I have a very large base dir called proj_base containing humongous amount of files and directories.

Mostly every day I create a proj_base_ndate and copy contents previous day folder proj_base_n-1date, and so forth.

For obvious memory limitations I want to change my foolish way of working. Now I want to copy the folder blindly, edit as required, and then in the end like to use diff to compare (suppose base_dir/f1/file1 = yesterday.c, base_dir/f2/file1= today.c), iteratively for all the files, and the non modified files, should be replaced by symlinks(like for instance today.c replaced by symlink of yesterday.c if no change in today.c), leaving the remaining files copied.

I found out there might be a problem (might be many) in this approach, as for each unmodified file its a symlink to previous file forming a chain of symlinks, so if it happened to change; the root would get changed affecting all the past files, so can it be avoided?

And also any feasible ways for adding or deleting files?

I hope may be this way I would be able to save some space, but any other ways or utilities are also welcomed.

Till now I am able to use

diff -s

to check if they are identical or not, but I’m not getting how to make it iterative in a loop in a bash script, with the corner cases.

Any suggestions would be very helpful. Thanks in advance.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP