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
  • 66,199
  • 35
  • 114
  • 250
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,732
  • 7
  • 32
  • 48
-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
  • 1
    This answer is identical to [your answer to another question](https://unix.stackexchange.com/a/592943/116858). 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