bashmacosfindmv

Auto overwrite when flattening file structure in OSX


I'm trying to flatten a directory in OS X which contains many duplicate files.

So far i have....

find /directory -mindepth 2 -type f -exec mv -i '{}' /directory ';'

But this responds asking me many times:

overwrite /directory/file.xml? (y/n [n]) 
not overwritten

Please can someone help me with the flag to auto accept yes/no to this and where it should be included in the above command?


Solution

  • You should use the option -f instead of -i for mv command

    find /directory -mindepth 2 -type f -exec mv -f '{}' /directory ';'
    

    In the manual of mv:

     -f      Do not prompt for confirmation before overwriting the destination path.  (The -f option overrides any
             previous -i or -n options.)
    
     -i      Cause mv to write a prompt to standard error before moving a file that would overwrite an existing file.
             If the response from the standard input begins with the character `y' or `Y', the move is attempted.
             (The -i option overrides any previous -f or -n options.)