1

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?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Umer
  • 157
  • 1
  • 7
  • 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 '19 at 15:25

2 Answers2

4

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
Prvt_Yadav
  • 5,882
  • NB: this solution does not preserve directory structure. It will put source/some/dir/file.ext into dest/file.ext. A lot of fun will happen if the source recursively contains multiple files named file.ext. – Ivan Krivyakov Sep 05 '23 at 03:21
-1

I am using Mac Terminal, and this command Is giving good result:

find FIle_Origin -type f -name "File_Name" -exec mv {} File_destination/ ;

Sudhs
  • 1
  • 1
    This answer is identical to your answer to another question. In this case I have not corrected its syntax as it doesn't at all try to address the issue in the actual question. In fact, as I pointed out in a comment to your other answer, it suffers from the same issue that the user in this question has. – Kusalananda Jun 15 '20 at 06:23