Skip to content

Instantly share code, notes, and snippets.

@lenerd
Last active August 29, 2015 14:20
Show Gist options
  • Save lenerd/b5a500dae59891e3b3a4 to your computer and use it in GitHub Desktop.
Save lenerd/b5a500dae59891e3b3a4 to your computer and use it in GitHub Desktop.
Compares the content of two directories.
#!/bin/sh
# ==============================================================================
# name: dir_diff.sh
# description: Compares the content of two directories.
# author: Lennart Braun <lenerd@posteo.de>
# license: MIT
# date: 20150501
# version: 0.1
# requirements: sha1sum
# usage: sh dir_diff.sh dir1 dir2
# ==============================================================================
# The MIT License (MIT)
#
# Copyright (c) 2015 Lennart Braun <lenerd@posteo.de>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# ==============================================================================
path1="${1%/}/"
path2="${2%/}/"
t1=$(mktemp)
t2=$(mktemp)
find $path1 -print0 | while IFS= read -r -d $'\0' line; do
sha1sum "$line" 2>&1 | sed -e "s!$path1!!" >> $t1
done
find $path2 -print0 | while IFS= read -r -d $'\0' line; do
sha1sum "$line" 2>&1 | sed -e "s!$path2!!" >> $t2
done
diff $t1 $t2
rm $t1
rm $t2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment