Posted by: image
linux question - 24/12/2003 13:39
i want to compare two directories, and tar up any added or changed files/symlinks/devs between the original and the modified. any easy way to do this? i'm basically looking for the same method that roger did with his base.tar.gz pack, so i can implement the changes i've done to the root partition of my empeg to the new alpha.
Posted by: mlord
Re: linux question - 24/12/2003 14:23
I would write a small shell script for this.
The script should do "diff --brief --recursive olddir newdir" and then parse the output into pathnames, and feed that as a filelist into "xargs tar cvf newdir.tar"
The output of diff will be a bunch of lines that look like this:
Only in olddir: Makefile
Only in newdir: morejunk
Files olddir/README and newdir/README differ
The script will have to convert that into this:
newdir/morejunk
newdir/README
Cheers
Posted by: image
Re: linux question - 25/12/2003 09:53
yeah, i figured that much. time to see how xargs works.
Posted by: mlord
Re: linux question - 25/12/2003 11:42
xargs is trivial, thank goodness. It just takes a series of pathnames (filenames), one per line on stdin, and appends them to the command line you supply as arguments. As in this example, which you can try out:
ls -1 | xargs echo
or this:
( ls -1 | xargs cat ) >junk
Cheers
Posted by: image
Re: linux question - 26/12/2003 10:17
yeah, i'm now looking at awk / sed to do the parsing of the list. dunno if i can do this as a oneliner anymore, but i'll sure try. also, i guess that diff doesnt list the dev files i installed (for telnetd), but i already have a script to handle that, so no worries. but if anyone already knows of a created script that does this <looks at Roger>, feel free to save me from the effort.
Posted by: wfaulk
Re: linux question - 26/12/2003 11:25
I'd say that the easiest thing to do would be to modify the source to diff to make its quiet output actually quiet. It's a little wordy now. If you just wanted to solve it for this one problem, it should be pretty easy to just edit out the talkiness. It shouldn't be a lot harder to modify it to make a new option.
Anyway, once you did that you could come up with a one liner. Something like ``newdiff --actually-quiet --recursive --brief | (cd newdir ; xargs tar cf dirdiffs.tar )''
Posted by: image
Re: linux question - 26/12/2003 20:17
its sloppy but i got it.
diff --brief --recursive OLDDIR NEWDIR | awk '/Only in NEWDIR/ {print $3 $4}; /differ/ {print $4}' | sed 's/:/\//' | sed 's/NEWDIR/./' | (cd NEWDIR && tar zcf diff.tar.gz)
ugly, but it works. no way to put a dev file in a tar archive, huh? also, it doesn't tar up symbolic links since diff just follows them.
Posted by: wfaulk
Re: linux question - 27/12/2003 10:31
Device nodes go into tar files just fine. Are you getting an error? It'll also store symbolic links, but I'm not sure what you're saying about diff following them.
Posted by: image
Re: linux question - 27/12/2003 13:12
since sbin is just a symlink to bin, diff detected dupes in both places, and tar duplicated both bin and sbin in the archive.