I have multiple directories that contain text files. Some of these directories are named differently yet contain the same text files. How do I remove all duplicated directories?

$ rmlint --types duplicatedirs <path>

That will list duplicate dirs and create a shell script (rmlint.sh) that you can optionally run to delete them.

See the user guide for installation instructions etc.


Try this first compare files byte by byte and if found same file then move the duplicated files to a backup path.

find /path/to/src -type f -exec cmp -s '{}' "/path/to/destA/{}" \; -exec echo mv -v "/path/to/destA/{}" "/path/to/backup/" \;
  • Ps, you need to run above for all your /path/to/destS. please note that if in case you had same files name in multiple destS with move command to /path/to/backup/ those will overwrite with same files name.
  • Ps, remove echo from the command to preforming actual move.

Then perform to run another find to delete empty directories.

find -type d -empty #-delete
  • Ps, remove the # from the command to perform actual deletion when you ensure it's displaying the empty directories and expected.

Later you can double check the files are moved to backup /path/to/backup/ path and once you confirmed with yourself, you can delete them with your wish as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.