UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 29th, 2005, 03:03 AM
DBStudent DBStudent is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 54 DBStudent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 1 m 34 sec
Reputation Power: 5
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!

Reply With Quote
  #2  
Old July 29th, 2005, 03:46 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 117 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 42 m 44 sec
Reputation Power: 6
Quote:
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.


Reply With Quote
  #3  
Old July 30th, 2005, 09:51 AM
iribach iribach is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 23 iribach User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 31 m 47 sec
Reputation Power: 0
Quote:
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.

Reply With Quote
  #4  
Old July 31st, 2005, 10:19 PM
DBStudent DBStudent is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 54 DBStudent User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 1 m 34 sec
Reputation Power: 5
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

Reply With Quote
  #5  
Old August 1st, 2005, 08:37 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 117 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 42 m 44 sec
Reputation Power: 6
Quote:
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > URGENT: how to compare the content of two directories in solaris


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT