I have 102 directories that I would like to merge into a single directory. If there are conflicts I would like to use the most recent file.

How can I do this?

Previously I've tried searching for the folders then copying them into the same parent directory, since the directories I want to merge have the same name it asks if I want to merge them. However it doesn't have an option to automatically keep the most recent file.

  • 2
    You can try to write a bash script to do it, I think nautilus isn't smart enought to do something like this. – Evandro Silva Oct 16 '12 at 12:35

You can do it with a command line :

find orig/ -type f  -exec cp -u -a \{\} dest/ \;

where orig is the directory containing the stuff you want to flatten and copy, and dest your destination directory. So what this will do is:

  1. find each file in orig/ and its sub-directories
  2. for each file, call copy (cp) to dest with the following options: u mean update, ie only copy if the file in newer, a archive, ie keep attributes, among them the dates of creation / modification

Small test here worked, but of course, be careful, and be sure to have a backup in case :-)

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.