Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 12 Dec 2019, 01:33
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
compare directory contents plus copy differences?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [2 Posts]  
Author Message
scsijon

Joined: 23 May 2007
Posts: 1536
Location: the australian mallee

PostPosted: Thu 21 Feb 2019, 21:56    Post subject:  compare directory contents plus copy differences?  

HI, coding problem.

I have
Code:

diff <(cd directory1 && find . | sort) <(cd directory2 && find . | sort)


Which compares two directories and tells me what's missing.
Currently I change it to
Code:

diff <(cd directory1 && find . | sort) <(cd directory2 && find . | sort) >difffile


To give me a file listing the missing files.

What I want to do is take this one step further and after creating another pair of directories called directory1-missing-directory2 and directory2- missing-directory1 have these new directories populated with a copy of whats missing.

so I think it becomes something like

Code:

#!/bin/sh
#involk as cmpsrt directory1 directory2
#outputs directories dir1-missing-dir2 and dir2-missing-dir1
#containing the contents missing in both ways
#
mkdir $1-missing-$2
mkdir $2-missing-$1
diff <(cd $1 && find . | sort) <(cd $2 && find . | sort)
???


But I don't know what to put in the ??? part?

Or is there a better way?

Can I have some help please.

thanks in advance.
Back to top
View user's profile Send private message Visit poster's website 
6502coder


Joined: 23 Mar 2009
Posts: 651
Location: Western United States

PostPosted: Thu 28 Feb 2019, 19:40    Post subject:  

Here's a crude script that illustrates a solution:

Code:
#!/bin/sh
# arguments are dir1 and dir2, relative to pwd
if [ $# != 2 ]; then
    echo "needs 2 args"
    exit 1
fi
D=/tmp/diff_$$
mkdir $D
list1=$D/list1
list2=$D/list2
listall=$D/listall
listdiff=$D/listdiff
list1not2=$D/list1not2
list2not1=$D/list2not1
cd $1
find . >$list1
cd -
cd $2
find . >$list2
cd -
cat $list1 $list2 | sort >$listall
uniq -u $listall > $listdiff
cat $list1 $listdiff | sort | uniq -d >$list1not2
cat $list2 $listdiff | sort | uniq -d >$list2not1
# Now list1not2 contains the list of files in d1 but not in d2
# and similarly for list2not1

It doesn't actually create and populate the difference directories, but once you've got the two files that list the deltas, the rest is trivial. I leave that and the elimination of the tmp files as an exercise for the reader.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [2 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0288s ][ Queries: 11 (0.0058s) ][ GZIP on ]