Search code examples
linuxunix

How to move (and overwrite) all files from one directory to another?


I know of the mv command to move a file from one place to another, but how do I move all files from one directory into another (that has a bunch of other files), overwriting if the file already exists?


Solution

  • It's just mv srcdir/* targetdir/.

    If there are too many files in srcdir you might want to try something like the following approach:

    cd srcdir
    find -exec mv {} targetdir/ +
    

    In contrast to \; the final + collects arguments in an xargs like manner instead of executing mv once for every file.