Find the answer to your Linux question:
Results 1 to 4 of 4
Anyone here with a clue? diff -r dir1 dir2 Gives me the files present in one dir but not in the other (recursive), but.... What command do I use so ...
  1. #1
    Just Joined!
    Join Date
    Jan 2011
    Posts
    2

    compare dir + files?

    Anyone here with a clue?

    diff -r dir1 dir2
    Gives me the files present in one dir but not in the other (recursive), but....
    What command do I use so the differences between files present in both dirs are generated in an outputfile?

    I have to dirs with thousands of files and want to find out which files have different content and what these differences are.

    Thnx
    Eelco

  2. #2
    Linux Guru Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    2,097
    Hmm, maybe subversion can be (ab)used for this, assuming these are (mainly) textfiles?


    Init a repository with dir1.
    Then checkout that repo to a working directory.
    delete all files in that working directory (preserving the .svn dirs)
    copy all files from dir2 to the working dir (rsync comes to mind)
    svn add
    then finally do a svn diff

    Other than that, "meld" can do what you want, but graphically (and a bit slow on many files)
    Last edited by Irithori; 01-13-2011 at 10:54 PM.
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Jan 2011
    Posts
    2
    Thanks Irithori,
    I will try this this weekend.
    Eelco

  4. #4
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    The GNU diff I use displays the detailed differences in content of files in directory trees. This scripts uses diff to look at a set of directories:
    Code:
    #!/bin/sh
    
    # @(#) s3	Demonstrate GNU diff.
    
    set +o nounset
    LC_ALL=C ; LANG=C ; export LC_ALL LANG
    echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
    echo "(Versions displayed with local utility \"version\")"
    version >/dev/null 2>&1 && version =o $(_eat $0 $1) diff 
    set -o nounset
    echo
    
    if [ ! -d d1 ] 
    then
      echo " Directory d1 does not exist, run initialization script."
      exit 1
    else
      echo " Tree d1, d2 contents:"
      tree -a d1 d2
    fi
    
    echo
    echo " Results with diff, details:"
    diff -r d1 d2
    # diff -ry d1 d2	# side-by-side display
    
    exit 0
    producing:
    Code:
    % ./s3
    Environment: LC_ALL = C, LANG = C
    (Versions displayed with local utility "version")
    OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
    Distribution        : Debian GNU/Linux 5.0 (lenny) 
    GNU bash, version 3.2.39(1)-release (x86_64-pc-linux-gnu)
    diff (GNU diffutils) 2.8.1
    
     Tree d1, d2 contents:
    d1
    |-- d11
    |   |-- d111
    |   |   |-- f111
    |   |   |-- h1
    |   |   `-- j1
    |   `-- f11
    `-- f1
    d2
    |-- d11
    |   |-- d111
    |   |   |-- f111
    |   |   |-- g1
    |   |   |-- h1
    |   |   `-- j1
    |   `-- f11
    `-- f1
    
    4 directories, 11 files
    
     Results with diff, details:
    Only in d2/d11/d111: g1
    diff -r d1/d11/d111/h1 d2/d11/d111/h1
    1c1
    < apple
    ---
    > orange
    Perhaps I misinterpreted your question.

    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

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