Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Compare directories; Show files in one directory that aren't in the other?

  1. #1
    Join Date
    Mar 2016
    Beans
    149

    Compare directories; Show files in one directory that aren't in the other?

    I have two directories, I want to know which files are in either directory that aren't in the other, including subdirs.

    So basically a diff, but with directories. Actually I thought of just running find ./ -name "." > dir1.txt and just running a diff but- diff will "complain" (wrong word) about two lines being different, which isn't what I want, you see- it would have so many false positives.

    I figure it's a common need, so maybe there's a way in the terminal or some application? (I'm in Ubuntu 18.04 - in fact the reason I'm doing this as part of backing up to get out of the stone age)

    Or do I have to just write a PERL (or whatever- PHP) script to recursively travers the dirs and etc etc etc.

    Thanks.

  2. #2
    Join Date
    Jun 2007
    Location
    Arizona U.S.A.
    Beans
    5,755

    Re: Compare directories; Show files in one directory that aren't in the other?

    Perhaps meld can help.

  3. #3
    Join Date
    Mar 2010
    Location
    USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Compare directories; Show files in one directory that aren't in the other?

    This is something that Midnight Commander excels at: <Cntrl><X>,<D>...

    Or via CLI using diff
    Code:
    diff --brief --recursive <Dir1> <Dir2>
    # Or more granularity by adding options or filters
    diff --brief --recursive <Dir1> <Dir2> --exclude '*.log'

    "Concurrent coexistence of Windows, Linux and UNIX..." || Ubuntu user # 33563, Linux user # 533637
    Sticky: Graphics Resolution | UbuntuForums 'system-info' Script | Posting Guidelines | Code Tags

  4. #4
    Join Date
    Jul 2005
    Location
    I think I'm here! Maybe?
    Beans
    Hidden!
    Distro
    Xubuntu 22.04 Jammy Jellyfish

    Re: Compare directories; Show files in one directory that aren't in the other?

    Thunar, the file manager from Xfce can now also show directories side by side in two pane mode (F3) which i use quite a lot.
    It is available in xfce-4.18, so needs a newer system than your 18.04 but could be useful in future.

  5. #5
    Join Date
    Mar 2016
    Beans
    149

    Re: Compare directories; Show files in one directory that aren't in the other?

    Quote Originally Posted by MAFoElffen View Post
    This is something that Midnight Commander excels at: <Cntrl><X>,<D>...

    Or via CLI using diff
    Code:
    diff --brief --recursive <Dir1> <Dir2>
    # Or more granularity by adding options or filters
    diff --brief --recursive <Dir1> <Dir2> --exclude '*.log'
    As I said in the op post, diff doesn't work because it returns too many false positives.

    If the one directory is

    filea
    fileb
    filec
    filed
    filee
    filef
    fileg
    fileh
    filei

    And the other is:

    filea
    filec
    filed
    filee
    filef
    fileg
    fileh
    filei

    (meaning without the "fileb"),

    Then diff will give notifications about every line after filea.

    When really what I want to know is that one directory has fileb and the other doesn't, you see?

  6. #6
    Join Date
    Mar 2011
    Location
    U.K.
    Beans
    Hidden!
    Distro
    Ubuntu 22.04 Jammy Jellyfish

    Re: Compare directories; Show files in one directory that aren't in the other?

    I use dual pane Krusader which I think can be configured to achieve that.

    There are useractions and I have previously written two useractions which can

    MeldFiles
    MeldDirectories

    or you can write your own custom scripts (useractions).

    Here is a typical MeldFiles command:

    meld %lCurrent% %rCurrent%

    and MeldDirs

    meld %lPath% %rPath%

    See UserActions here...

    https://docs.kde.org/stable5/en/krusader/krusader//

    https://docs.kde.org/stable5/en/krus...eractions.html

    Instead of Meld (CLI) you might run Python scripts.
    I understand that you are looking for files which are not common.
    Another idea is to use Albert. But Krusader allows two directories to be easily selected.
    Krusader is similar to Midnight Commander as suggested earlier.
    Last edited by dragonfly41; December 18th, 2023 at 12:50 AM.

  7. #7
    Join Date
    Mar 2016
    Beans
    149

    Re: Compare directories; Show files in one directory that aren't in the other?

    Woa, ActionScript?! That's still alive? I used to write a whole lot of it before Flash and Flex died.

    Yea I'm looking at some of these and it looks like it can only do one directory at a time. But yea, I'll take a look at those, thanks.

    Oh and like I said- rolling my own code (in my case not python- PERL or PHP) is my last resort but I figured the task is commen enough that there might be something.

    Thanks

    (wow, Actionscript!)

  8. #8
    Join Date
    Dec 2014
    Beans
    2,611

    Re: Compare directories; Show files in one directory that aren't in the other?

    Normally I'd do something like
    Code:
    (ls -1 firstdir;ls -1 seconddir)|sort|uniq -u
    but this has the disadvantage that you can't tell in which directory the unique file(s) is(/are).
    A bit of interactive python doesn't have this problem:
    Code:
    import os
    # replace firstdir and seconddir with the paths to the directories in question
    a=os.listdir('firstdir')
    b=os.listdir('seconddir')
    # this prints the files in firstdir that are not in seconddir
    print([x for x in a if x not in b])
    # the ones in seconddir but not in firstdir
    print([x for x in b if x not in a])
    Turning this into a script that gets arguments from sys.argv[] to use as firstdir and seconddir is left as an exercise to the reader.

    Holger

  9. #9
    Join Date
    Dec 2005
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: Compare directories; Show files in one directory that aren't in the other?

    Quote Originally Posted by david503 View Post
    I have two directories, I want to know which files are in either directory that aren't in the other, including subdirs.
    Beyond Compare can do this, I've used it for years. The download is at https://www.scootersoftware.com/download/ , from memory it's a 30 day usage for the trial/free.

  10. #10
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Compare directories; Show files in one directory that aren't in the other?

    My first thought was to use meld. I know that works.

    Then I had an idea to use rsync in "dry-run" mode (think it is the -n option) which doesn't do anything. With the verbosity set correctly, the list of files to be transferred will be output. Then swap the source/target around and get the opposite list. Simple. Elegant. Effective.

    Code:
            -n, --dry-run               perform a trial run with no changes made
    OT: I love me some BASS!

Page 1 of 2 12 LastLast

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
  •