This should be fairly straightforward, but I can't seem to get it. Little context, I got files let's say test1.txt...test5.txt distributed over several directories. I just want to find them, and move them to one directory.
I can use xargs with find but I want to use the -exec option in find. In which all the found files will be passed in one "instance" of mv command (correct me if I'm wrong), so here's the command:
find . -name 'text*.txt' -exec mv '{}' collectedDir;
I get this error: find: -exec: no terminating ";" or "+". I clearly am using a semicolon. So what could be the issue causing this?
Before you ask, find did find all the files, I used print to check, and collectedDir does exist.
Your shell is seeing that ; before find does and swallowing it.
You need to escape it \; so the shell doesn't eat it.
That said -exec .. \; will run the command once for each file found not once total.
To run it once for as many files as possible you need -exec ... +.
find . -name 'text*.txt' -exec mv '{}' collectedDir +