Skip to content

Instantly share code, notes, and snippets.

@janbuecker
Created December 6, 2016 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janbuecker/d2a4ef5519ea9778637dece6bed4f54b to your computer and use it in GitHub Desktop.
Save janbuecker/d2a4ef5519ea9778637dece6bed4f54b to your computer and use it in GitHub Desktop.
compare_folders.sh
// Usage: compare_folder <dir1> <dir2>
//
// Output:
//
// $ compare_folder dir1 dir2
//
// Changes in permissions
// drwxr-xr-x/update | drwxr-xr-x/update_original
// -rwxrwxr-x/console | -rw-r--r--/console
// -rwxrwxr-x/clear_cache.sh | -rw-r--r--/clear_cache.sh
//
// Changes in contents
// Files update/engine/Shopware/Application.php and update_original/engine/Shopware/Application.php differ
// Files update/engine/Shopware/Components/Check/Data/Files.md5sums and //update_original/engine/Shopware/Components/Check/Data/Files.md5sums differ
// Files update/update-assets/snippets.sql and update_original/update-assets/snippets.sql differ
#!/bin/bash
function removeTemporaryFiles() {
rm a.diff b.diff
}
function printUsage() {
echo "Usage: $(basename $0) <dir1> <dir2>"
}
if [[ $1 == "" ]] || [[ $2 == "" ]]; then
printUsage;
exit 1;
fi
find $1 -ls -type f | awk '{ gsub("^.*/","",$11); printf "%s/%s\n", $3, $11; }' > a.diff
find $2 -ls -type f | awk '{ gsub("^.*/","",$11); printf "%s/%s\n", $3, $11; }' > b.diff
echo "Changes in permissions"
diff -y --suppress-common-lines a.diff b.diff
echo
echo "Changes in contents"
diff -rq $1 $2
removeTemporaryFiles;
exit 0
@bcremer
Copy link

bcremer commented Dec 6, 2016

No need for temporary files:

#!/usr/bin/env bash

function printUsage() {
    echo "Usage: $(basename $0) <dir1> <dir2>"
}

if [[ $1 == "" ]] || [[ $2 == "" ]]; then
    printUsage;
    exit 1;
fi

$diffA=$(find $1 -ls -type f | awk '{ gsub("^.*/","",$11); printf "%s/%s\n", $3, $11; }');
$diffB=$(find $2 -ls -type f | awk '{ gsub("^.*/","",$11); printf "%s/%s\n", $3, $11; }');

echo "Changes in permissions"
diff -y --suppress-common-lines $diffA $diffB

echo "Changes in contents"
diff -rq $1 $2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment