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/