Skip to content

Instantly share code, notes, and snippets.

@sblack4
Created May 3, 2020 16:02
Show Gist options
  • Save sblack4/8cac505c4ea12e5d4997abbfa83dcec8 to your computer and use it in GitHub Desktop.
Save sblack4/8cac505c4ea12e5d4997abbfa83dcec8 to your computer and use it in GitHub Desktop.
Compare file types with bash

Compare File Types

Create the following script. The names uat and prod simply refer to the two filesystems this script was developed to test. They can be renamed to anything.

#!/bin/bash
uat=`file -bi "/mnt/my_files/${1}"`
prod=`file -bi "/mnt/my_other_files/${1}"`
if [[ "$uat" == "cannot open (No such file or directory)" || "$prod" == "cannot open (No such file or directory)" ]]
then
    echo $1 >> /data/errors.txt
elif [[ "$uat" != "$prod" ]]
then
    echo $1 >> /data/mismatches.txt
else
    echo $1 >> /data/matches.txt
fi

Then use find to pipe every file through said script:

cd /mnt/my_files
find . -type f -exec /data/compare.sh "{}" \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment