Created
December 20, 2019 18:10
-
-
Save dumrauf/ac3ebd2fac5583e31fd506c9ed046f3c to your computer and use it in GitHub Desktop.
Find out if two directories contain the same files or where they differ; see https://www.how-hard-can-it.be/basic-directories-diff/ for details
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Input parameter validation | |
if [ "$#" -lt 2 ]; then | |
script_name=$(basename "$0") | |
echo "Usage: ${script_name} <directory-one> <directory-two>" | |
echo "Example: ${script_name} one/ two/" | |
exit -1 | |
fi | |
# Input parameter assignment | |
directory_one=$1 | |
directory_two=$2 | |
# Get the contents of the two directories | |
contents_directory_one=$(cd "${directory_one}" && find . | sort) | |
contents_directory_two=$(cd "${directory_two}" && find . | sort) | |
# Diff the contents of the two directories | |
difference=$(diff -u <(echo "${contents_directory_one}") <(echo "${contents_directory_two}")) | |
# Provide some visual feedback to the user | |
if [ -z "${difference}"] | |
then | |
echo "Both directories are identical." | |
else | |
echo "The directories differ!" | |
echo "${difference}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment