Results 1 to 7 of 7

Thread: Show the difference of two folders

  1. #1
    Join Date
    Dec 2011
    Beans
    86

    Show the difference of two folders

    I have got my home directory into a bad situation with a mistyped rm command. I have now got as far as getting a backup onto an external hard drive as regular files.

    So I have:

    • Folder A: Current home directory: some files missing
    • Folder B: Old home directory: some files out of date or don't exist in current home directory


    There are plenty of ways I've come across using diff, find etc. to compare the contents of two directories (/home/duncan/ and /media/FreeAgent\ GoFlex\ Drive/old_home/home/duncan/) but that's not what I want.

    I am not interested if a file exists in Folder A but not Folder B. I am not interested in anything inside a "dotfile" or "dotfolder". I am not interested in files where the contents differ.

    I am only interested in files that exist in Folder B but not Folder A.

    How can I check for this, without wasting resources checking various files byte-for-byte?

    Thanks,
    Duncan

  2. #2
    Join Date
    Dec 2011
    Beans
    86

    Re: Show the difference of two folders

    bump

  3. #3
    Join Date
    Oct 2008
    Beans
    3,509

    Re: Show the difference of two folders

    Freefilesync has a compare feature prior to syncing where you can choose a view.
    eg in the attached pic I have chosen to only view files that will be newly created, not
    those that will be overwritten.
    ie it shows files that exist in the right pane but not the left.

    FreeFileSync PPA
    Attached Images Attached Images

  4. #4
    Join Date
    Sep 2006
    Beans
    7,909
    Distro
    Lubuntu Development Release

    Re: Show the difference of two folders

    What is the desired outcome? If you want the two directories to contain the same files you could run rsync.
    The Truth Shall Make Ye Fret.

  5. #5
    Join Date
    Apr 2012
    Beans
    5,866

    Re: Show the difference of two folders

    the best quick hack I could come up with is

    Code:
    #!/bin/bash
    
    dirA=/home/duncan/
    dirB=/media/FreeAgent\ GoFlex\ Drive/old_home/home/duncan/
    
    while read -r -d $'\0' file; do 
        [ -f "$dirA"/"$file" ] || echo "$dirA" : "$file" not found
    done < <(find "$dirB" -path '*/.*' -prune -o -type f -printf '%P\0')
    Probably rsync has an option to list the out-of-sync files without actually syncing, as well

  6. #6
    monkeybrain2012 is offline Grande Half-n-Half Cinnamon Ubuntu
    Join Date
    Oct 2012
    Beans
    874

    Re: Show the difference of two folders

    Try unison, it is in the repo.

  7. #7
    Join Date
    Apr 2011
    Location
    Maryland
    Beans
    1,461
    Distro
    Kubuntu 12.04 Precise Pangolin

    Re: Show the difference of two folders

    Quote Originally Posted by steeldriver View Post
    the best quick hack I could come up with is

    Code:
    #!/bin/bash
    
    dirA=/home/duncan/
    dirB=/media/FreeAgent\ GoFlex\ Drive/old_home/home/duncan/
    
    while read -r -d $'\0' file; do 
        [ -f "$dirA"/"$file" ] || echo "$dirA" : "$file" not found
    done < <(find "$dirB" -path '*/.*' -prune -o -type f -printf '%P\0')
    Probably rsync has an option to list the out-of-sync files without actually syncing, as well
    Hmmmm....that actually gives me an idea. I don't have time to test this, but it might be informative just the same. If you include the -n option in Rsync, you'll get a dry run that will just show you what would happen if you actually run the script. Rsync also allows you to easily exclude elements from tne backup. So, if you were to run rsync in dry run mode, excluding what you don't care about and then capture the output to a text file, that might show you what files are different.

    Also, have you tried using the -q option of 'diff', which does show which skips the contents of the files and just shows which files are in A but not B and so on. There is also the -x option which will allow you exclude files that match a pattern. From the GNU documentation:

    http://www.gnu.org/software/diffutil...rectories.html

    So, I think you might be able to exclude the dot files and directories with a '-x' option.

    Maybe you've tried all the diff options, already, though....

Bookmarks

Posting Permissions

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