#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    54
    Rep Power
    11

    URGENT: how to compare the content of two directories in solaris


    Hi,

    I would like to compare the two directories in solaris. Any script i can use to archieve this purpose?

    Hopefully the script can find the different of these two direcotries and will scan the sub folder too.


    Many many Thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Prague, Czech Rep.
    Posts
    117
    Rep Power
    12
    Originally Posted by DBStudent
    Hi,

    I would like to compare the two directories in solaris. Any script i can use to archieve this purpose?

    Hopefully the script can find the different of these two direcotries and will scan the sub folder too.


    Many many Thanks!

    Start with reading "man diff". If you have troubles, write again.

  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    23
    Rep Power
    0
    Originally Posted by zlutovsky
    Start with reading "man diff". If you have troubles, write again.

    read man diff
    to state: diff is the wrong tool, but you get a link to dircmp

    not clear what you want compare.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    54
    Rep Power
    11
    I want to compare two directories to find out:
    - new file
    - changed file
    - deleted file


    And then can display a summary after compare:

    Summary:
    New : 5
    Changed: 3
    Deleted : 1


    Thanks
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Location
    Prague, Czech Rep.
    Posts
    117
    Rep Power
    12
    Originally Posted by DBStudent
    I want to compare two directories to find out:
    - new file
    - changed file
    - deleted file


    And then can display a summary after compare:

    Summary:
    New : 5
    Changed: 3
    Deleted : 1


    Thanks
    Here you are:

    :
    usage () {
    echo "$0: call: $0 old_dir new_dir" >&2
    exit 1
    }

    # Check the arguments
    [ $# -eq 2 ] || usage
    [ -d $1 ] || usage
    [ -d $2 ] || usage
    # Store the directories
    OLDD=$1
    NEWD=$2
    # Contents of the old directory
    cd $OLDD
    find . >/tmp/cont_old
    # Contents of the new directory
    cd $NEWD
    find . >/tmp/cont_new

    # Determine what is only in the old directory
    comm -23 /tmp/cont_old /tmp/cont_new >/tmp/in_old
    # Determine what is only in the new directory
    comm -13 /tmp/cont_old /tmp/cont_new >/tmp/in_new
    # Determine what is in both directories
    comm -12 /tmp/cont_old /tmp/cont_new >/tmp/in_both

    # Evaluate the lists
    NEW=`cat /tmp/in_new | wc -l`
    DEL=`cat /tmp/in_old | wc -l`
    CHAN=0
    while read APP; do
    # Do not test the subdirectories
    [ -d $APP ] && continue
    # Get rid of './'
    APP=${APP#./}
    # Compare the plain files
    diff $OLDD/$APP $NEWD/$APP 1>/dev/null 2>&1 || {
    CHAN=`expr $CHAN + 1`
    }
    done</tmp/in_both

    # Output
    echo "New:" $NEW
    echo "Changed:" $CHAN
    echo "Deleted:" $DEL


    I give you the fish, but you should learn to catch one yourself. To begnin with, you can study and modify my scritpt. It should remove the working files on end, give the possibility to show the differences, try set -xv to see the intermediate results...

    I have tested it under Solaris, but it should run on every Unix.

    Regards

IMN logo majestic logo threadwatch logo seochat tools logo