Compare 2 directories and copy differences to directory 3
问题 I have three directories. I would like to compare directory1 with directory2, then take those changes/new files and copy them over to directory3. Is there an easy way to do this, maybe by using linux diff and cp commands? I'm open to ideas. Thanks! Andrew 回答1: I believe this is what you want from your description. for file in dir2/*; do file_in_dir1=dir1/$(basename ${file}) if [ ! -e ${file_in_dir1} ]; then # If the file in dir2 does not exist in dir1, copy cp ${file} dir3 elif ! diff ${file}