You could do something like below as well.
find path_A -name "*AAA*" -print0 | xargs -0 -I {} mv {} path_B
Where,
-0
If there are blank spaces or characters (including newlines) many commands will not work. This option take cares of file names with
blank space.
-I
Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks do not
terminate input items; instead the separator is the newline
character.
Testing
I created two directories as sourcedir
and destdir
. Now, I created bunch of files inside sourcedir
as file1.bak
, file2.bak
and file3 with spaces.bak
Now, I executed the command as,
find . -name "*.bak" -print0 | xargs -0 -I {} mv {} /destdir/
Now, inside the destdir
, when I do ls
, I could see that the files have moved from sourcedir
to destdir
.
References
http://www.cyberciti.biz/faq/linux-unix-bsd-xargs-construct-argument-lists-utility/
+
which dows the job, you can read my quote above orman find
instead – cuonglm Feb 11 '18 at 04:32-exec mv {} path_b +
and it was failing with permissions errors. TBH, I still don't understand why, but-exec mv -t path_b {} +
works a treat! – Jeremy Davis Apr 10 '18 at 00:55-exec ... {} +
, the{}
has to be the last thing before the+
. This is why he usesmv -t destdir {} +
and notmv {} destdir +
. One cold have used-exec mv {} destdir ';'
instead, but that would have executedmv
once for each file. – Kusalananda May 06 '18 at 12:40cp
as well. – András Váczi Jun 01 '21 at 07:39