Fri May 8 20:31:47 PDT 2015

Remote Recursive Directory Differences

The following bash script is useful - if you want to see if you have differences between files in two sets of directories trees on different machines.

It is not terribly sophisticated. It does not use any significant network bandwidth to do the comparison - because it uses a checksum calculation on each machine. It has two arguments. The first is the servername or the username@servername couplet depending on how you have set up your sshd's and so on. The second argument is the pathway to the directory that you want to compare with the current directory on your current machine.

All the script does is collect a set of sorted checksums on your present machine starting at the current directory, collect a similar set on the remote machine at the specified location, and then diff the two sets of checksums. If the directory trees are identical there will be no differences and you will be told this. If there are differences you will see the differing files in the output from the diff command.

As you can see the script is not really recursive, it simply uses find to collect all the files. However, the effect is that of a recursive directory differencing across a remote machine's directory, without consuming significant bandwidth.


#provide a simple, remote directory diff based on checksums

echo "arg1 is the username and host, e.g. user@server ": $1
echo "arg2 is the remote directory, complete path": $2

ssh $1 "cd $2; find . -exec cksum {} \\;" | sort -k3 > /tmp/dir1.txt
find . -exec cksum {} \; | sort -k3 > /tmp/dir2.txt

diff /tmp/dir1.txt /tmp/dir2.txt
if [ $ret -eq 0 ]
  echo "The directories are identical"

Comments are closed

If you would like to get in touch with me, please mail zfs at

recent comments

Posted by ZFS | Permanent link | File under: bash
[StumbleUpon] [Digg] [Reddit] [Facebook] [Google]