-->

Shell Scripts to print the files present in one directory but not present in other directory

Posted by Admin on
# cmp_dir - program to compare two directories and print the files
# which are present in first directory but not in second directory

# Check for required arguments
if [ $# -ne 2 ]; then
    echo "usage: $0 directory_1 directory_2" 1>&2
    exit 1
fi

# Make sure both arguments are directories
if [ ! -d $1 ]; then
    echo "$1 is not a directory!" 1>&2
    exit 1
fi


if [ ! -d $2 ]; then
    echo "$2 is not a directory!" 1>&2
    exit 1
fi

#check whether the files of 1st directory are present in 2nd directory
for filename in $1/*; do
    fn=$(basename "$filename")
    if [ -f "$filename" ]; then
       if [ ! -f "$2/$fn" ]; then
            echo "$fn is not there in $2"
       fi
    fi
done

No comments:

Post a Comment