Compare two huge directories on Linux
I have a huge document directory in my Linux which I copied from my external hard drive long long ago. My hard disk is almost full on my Linux. So I want to move these files to the external to save more space for my Linux. However, I am not sure the huge directory (almost 30GB+) is the same as that in the external drive and whether I have changed some file or not.
So I write this simple bash script. It can work even if the path have spaces.
#!/bin/bash - set -o nounset # Treat unset variables as an error dir1='/home/someone/Documents/' dir2='/run/media/someone/FAT32/Documents Backup/' # We assume the sub directories in dir1 and dir2 are all the same. for i in $(ls $dir1) do com1="${dir1}$i" com2="${dir2}$i" echo "comparing $i in those two paths." diff -ur "$com1" "$com2" echo "Finish comparing $i." done echo "FINISH....!!!"
Though these two directories is about 30GB. It doesn't take very long to finish. :-)