Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Delete duplicate directories?
New on LowEndTalk? Please Register and read our Community Rules.

Delete duplicate directories?

xrzxrz Member
edited August 2016 in Help

Is there a way via some bash script or just cmd to find duplicate directories and delete?

i have main folders:
TEST1
TEST2

In folder TEST1 is some amount of same folders as in folder TEST2

can be this done? i tried fdupe but it only search for dupe files not whle dirs

thx!

Comments

  • FalzoFalzo Member
    edited August 2016

    that use case is some kind of odd and probably hard to achieve.

    how should a script determine what you want to have removed from which of both folders? what esp. should happen with folders that include more or slightly different files, shall they be delete to or only the files or should they be left untouched?

    easiest way may be to remove files with fdupes like you intended and afterwards remove only empty dirs (which probably are the ones left over) via

    find test1 -type d -empty -delete

    if you only want to spare on diskspace I recommend looking into hardlinking duplicate files, but please do try to understand the concept of hardlinking before using it ;-)

    I can recommend jdupes over fdupes for handling duplicate files anyways: https://github.com/jbruchon/jdupes

  • exception0x876exception0x876 Member, Host Rep

    or you use a filesystem with automatic file de-duplication support

  • @xrz said:
    Is there a way via some bash script or just cmd to find duplicate directories and delete?

    i have main folders:
    TEST1
    TEST2

    In folder TEST1 is some amount of same folders as in folder TEST2

    can be this done? i tried fdupe but it only search for dupe files not whle dirs

    thx!

    Depends upon the programming language used

    You could alwats run php from cli and pass two dirs with their paths and simply map their directory structure in a single multi dimensional array and if both match then remove one....

    But you need to do lots of coding yourself :-)

  • Like Falzo says, it depends on what you actually want the end result to be. Any time I'm looking to do things with mostly identical file hierarchies, I consider if rsync can get it done. Perhaps your problem can be solved by making both directories duplicates of each other, and then just deleting one of them.

Sign In or Register to comment.