1

I have some 70,000 files (basically duplicates) most of which match a name pattern like name(1).ext, name(2).ext .... name(10).ext. However among these files there are others named name (xwz).ext.

Now what I want to do is finding all the first type files and move all of them to a destination folder; I looked to several answers on superuser and I manage to do the following:

first I used the find command to find the files this way:

find ~/sourcedir -name "*([0-9]).*" -o -name "*([0-9][0-9]).*"

which retrieve all the files I want (I printed them on a file and got more than 73,000 files); then I tried to pass them to the Move command this way:

find ~/sourcedir -name "*([0-9]).*" -o -name "*([0-9][0-9]).*" -type f -exec mv {} ~/destinationdir \;

however doing that, just one file is moved to destination (the last one in the list) or none ; what's wrong here? why can't I move all the files in destination dir ?

yet, if I use only one option in the find command, say:

find ~/sourcedir -name "*([0-9]).*" 

and then do the -execmv it works, but not if use both options;

indeed it looks like it's processing just the second option (as the only moved file is the one which match the second option); how can I pass all the files matching either the first or the second option to 'move'?

bigo
  • 19
  • 1
  • offhand, I'd try bracketing the two -name options with **`\(`** and **`\)`**, as well as experimenting with putting an **`echo`** before the **`mv`** to verify that it's executing the command I intended. – Thomas Dickey Dec 16 '18 at 17:24
  • yes indeed, I didn't realize that the find command stops if the first condition is matched. Thanks now I tried this and it works: find `code` \ ( -name "*([0-9]).*" -o -name "*([0-9][0-9]).*" \) -type f -exec mv {} /destination \; `code` anyhow I suspect conditions can be managed better with -regex but I don'y know how to use. Thanks all, I had searched before posting but couldn't find the right answer; – bigo Dec 16 '18 at 18:04

0 Answers0