Help with diff command
Results 1 to 4 of 4

Thread: Help with diff command

  1. #1
    Banned
    Join Date
    May 2005
    Posts
    12

    Help with diff command

    Ok heres my situation
    I have 2 operating systems on my box. Slackware 10 and Windows XP Pro.
    Pro was installed first and I had just recently installed Slackware

    When installing Slackware I have my windows partion mounted as /fat-c (although its nfts). And its read-only.

    Problem: I have my up-to-date music folder on the /fat-c and my not so up date Music folder in my /home directory on Slackware. I want to be abe to run a command that compares the two folders, finds differences and copies the differences into the slackware folder.

    I want to use diff and pipe it into cp or vise versa.
    I tried
    cp -r |diff Music1 Music2| cut -d: f1

    But it didnt work. Any suggestions?

  2. #2
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    Hi

    Interesting little project - file synchronisation tool with diff
    I like such things, so I did something...

    Code:
    diff -r first second  |awk '{if ($1=="Only"){source=$3;sub(/:/,"",source);target=source;
    if ($3~/^first/) {sub(/first/,"second",target);print "cp -r "source"/"$4" "target} else 
    if ($3 ~ /^second/) {sub(/second/,"first",target);print  "cp -r "source"/"$4" "target}}}' |sh
    
    (all on one line)
    replace all occurances of "first" and "second" with you folder names.
    If you want to see what it does without having it doing it,
    remove the "|sh" at the end (recommended!). And of course,
    it may not work correctly in some cases...


    Maybe it is of advantage to use the standard tools, like rsync, unison...Have a look
    at this list[1]. On windows, I like Foldermatch[2].

    Cheers

    [1] http://linas.org/linux/, Data Mirroring, Replication and File Synchronization
    [2] http://www.foldermatch.com/
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  3. #3
    Banned
    Join Date
    Jun 2004
    Posts
    154
    Thanks I'll try it out

  4. #4
    Senior Member gore's Avatar
    Join Date
    Oct 2002
    Location
    Michigan
    Posts
    7,177
    Originally posted here by aura2
    Thanks I'll try it out

    Got your multiple accounts mixed up huh? Let me help you sort this out.

    rm -rf you*

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •