I need to copy all files and directory from source let's say
/var/www/html/test/ to destination
/var/www/html/test2/. Destination can already have extra files and folders which i need to remove after copying the files from source.
I cannot delete everything from destination before copying it.
I tried following :
1) Copied the file from source to destination using
cp -R source destination
which working fine.
2) I tried to iterate over all the files in destination file to check if the file is exist in source. If not remove the file from destination
for file in /var/www/html/test2/*; do filestr=`basename $file`;echo $file; if [ `ls /var/www/test1/ | grep -c $filestr` -eq 0 ]; then rm $file; fi; done;
which working fine for the root files in the destination only.
Need to find out how to recursively check all file and directory matching with source or not.