Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing directory structure 2

Status
Not open for further replies.

jarekST

Technical User
Nov 4, 2003
4
PL
Hello,

do you know command (is there any) in AIX which as a result would return differences between two directories and its subdirectories?
I would like to compare two large filesystems and find out which directory/file is missing/changed since the time tar has been made.

diff dir1 dir2
gives no result when only size or date/time is different :(

Maybe anyone have a short script for that? I would appreciate it.

Thank you in advance.
jarekST
 
do ls -l on both dirs. capture the output to 2 files. diff the files. the time stamps will be picked up by diff

Before you criticize someone, you should walk a mile in their shoes. That way you're a mile away and you have their shoes.
 
Thank you for your advice.

I thought there could be any designed command for this purpose. Actually I wrote and use following script to do it:

ls -l -R /dir1 | awk '{print $1, $6, $7, $8, $9}' > listing1
ls -l -R /dir2 | awk '{print $1, $6, $7, $8, $9}' > listing2
diff listing1 listing2 > diff.lst

The problem is that when there is missing any file in one of directories diff returns all differences and a lot of line completely unwanted (with file which are allright). As a result I have to repair first difference and execute the script again... and again... and again...

Maybe you have any other suggestion, hint?
Sometimes life is brutal... even a mile away and with a new pair of shoes walking in :))

Thanks a lot!
 
I think the cmp command may have the same problem as diff. here is what I would try.

you want to catch files in dir1 but missing in dir2 and files in dir2 but missing in dir1. If the file exists in both dirs you want to see if there is any difference in fields ( perms, date, etc )
you can write a script, but it is kinda nasty. It takes 2 passes. ( ok you might do it in less than one, but I dont know how )

do you know how to script in ksh?

if so, here is a draft.

first, list the dirs into files as you did
ls -l -R /dir1 | awk '{print $1, $6, $7, $8, $9}' > listing1
ls -l -R /dir2 | awk '{print $1, $6, $7, $8, $9}' > listing2

then for every file in listing1, see if the file name is in listing2. If its NOT there output an error. If it is there, check the two lines for differences. If they are different, print an error.

next for every line in listing2 see if the file exists in listing1. if not, print an error.
you dont need to check for differences in this loop because you caught them all in the first loop.

hope this helps


Before you criticize someone, you should walk a mile in their shoes. That way you're a mile away and you have their shoes.
 
find /dir1 -type f > file1
find /dir2 -type f > file2
cat file1 file2|sort|uniq -u # plain list
cat file1 file2|sort|uniq -u|xargs -n 1 ls # ls each file

IBM Certified -- AIX 4.3 Obfuscation
 
Thank you to all of you.

The problem with above is that /dir1 and /dir2 have different names so:

cat file1 file2|sort|uniq -u

has no effect and there are still all files listed.
Anyway you were very helpful and now I try to write the script for the future.

Big thanks once again and all the best.
Bye!
 
ah yes sorry.

cd /dir1
find . -type f > file1
cd /dir2
find . -type f > file2
cat file1 file2|sort|uniq -u

if the subdirs have different names, i will have to get much more creative.

IBM Certified -- AIX 4.3 Obfuscation
 
Thank you for all!

Now I have two scripts :))

#########################################################
##### using sdiff command (comtec17 solution)
#########################################################
ls -l -R ./dir1 | awk'{print $1, $6, $7, $8, $9}' > listing1
ls -l -R ./dir1 | awk'{print $1, $6, $7, $8, $9}' > listing2
sdiff -s listing1 listing2 > diff.lst

#########################################################
##### using find command (Yegolev solution)
#########################################################
cd ./dir1
find . -type f > listing1
cd ../dir2
find . -type f > listing2
cat listing1 listing2 | sort | uniq -u | xargs -n 1 ls -l | awk'{print $6, $7, $8, $9}' > diff.lst

Both od them are ok! BIG Star for you. Thanks!
Bye!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top