0

I'm trying to find and move some files from /home/user/fol1 to /home/user/fol2.

Generally I would use

find . -type f -name "abc*" -exec mv -t "/path/to/foo/bar" {} +

but this overwrites files with same names already present in /path/to/foo/bar.
I want it to skip the files if already present there.

If this requires a loop, I also need an output either plain output on shell or in a log file.

Any ideas?

  • Do you want to have all files in a single directory /path/to/foo/bar even if they were in subdirectories? Example: File baz/abcdef would be moved to /path/to/foo/bar/abcdef. Or would you want /path/to/foo/bar/baz/abcdef? In case you don't have files in subdirectories you would not need find. – Bodo Jan 17 at 15:25
3

You can use n option:

find . -type f -name "abc*" -exec mv -nt "/path/to/foo/bar" "{}" +

From man mv:

-n, --no-clobber
          do not overwrite an existing file

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.