Moving millions of files to a different directory with specfic name patterns
You should use:
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' \
-exec mv -t destination "{}" +
So maxdepth 1
means that you want to search in current directory no subdirectories.
type f
means find only files.
name '??????????_a1ac*.jpg'
is a pattern that matches with file you are searching.
mv -t destination "{}" +
means move matched files to destination. Here +
adds new matched files to previous one like:
mv -t dest a b c d
Here a b c d are different files.
Your command,
find . -maxdepth 1 -type f | ??????????_a1ac*.jpg |xargs mv -t "/home/ubuntu/ntest"
Pipes the list of all the files TO all the files!
find . -maxdepth 1 -type f -name `*_a1ac*.jpg` -print0 |\
xargs -0 -r mv -t "/home/ubuntu/ntest"
will do the trick.
You're very close. You should use the -name
option to find
. And remember to quote the pattern.
So
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' |xargs mv -t "/home/ubuntu/ntest"