Para sincronizar dos directorios, ejecuto
diff -r -q path/to/dir1 path/to/dir2 1>/dev/null
if [[ $? == "0" ]]
then
echo "Directories are exact copies of each other"
else
rsync -av --delete path/to/dir1 path/to/dir2
fi
Sin embargo, si ejecuta el script nuevamente, diff dice que los directorios siguen siendo diferentes.
Sin embargo, al crear dos carpetas vacías testy sync, diff dice que son lo mismo.
sync
rsync
bash-scripting
diff
Narusan
fuente
fuente

rsync -ar --delete path/to/dir1 path/to/dir2, -r significa --recursivo. Para obtener más información, consulte el manual de rsync (Para abrir el uso manualman rsync).