Interactive directory merging

Here’s an ‘interactive’ directory merging tool that doesn’t require GUI libraries, printer subsystems, and so forth. It is useful when you want to do things the easy way, at a terminal, without taking your hands off your keyboard. And it works on systems where you don’t have access to install things yourself, such as a shared webhosting server.

echo "#!/bin/bash" > /tmp/mergedir
diff --brief --recursive $1 $2 | awk '/differ/ {print "vimdiff " $2 " " $4 ";"}' >> /tmp/mergedir
chmod +x /tmp/mergedir

Create that as a shell script, chmod +x it, put it in your PATH, and invoke it like this, assuming you called it mergedir:

$ mergedir /some/directory /other/directory

When it finds files that differ, it will open vimdiff on them, and you can use the standard vimdiff commands to merge them (commands such as dp, do, :w, :qa, ]c and so forth – look in the Vim manual for more information).

I'm Baron Schwartz, the founder and CEO of VividCortex. I am the author of High Performance MySQL and lots of open-source software for performance analysis, monitoring, and system administration. I contribute to various database communities such as Oracle, PostgreSQL, Redis and MongoDB. More about me.