How can I move many files without having too many arguments?

I am trying to move about 700,000 .jpg files from one directory to another on my Ubuntu server. I tried the following:

xargs mv * -t /var/www/html/ 

and

 echo (*.jpg|*.png|*.bmp) | xargs mv -t /var/www/html/ 

and

 echo (*.jpg) | xargs mv -t /var/www/html/ 

and

 find . -name "*.jpg" -print0 | xargs mv * ../ 

and they all give me the same error: / usr / bin / xargs: list of arguments too long

what should I do? Please help me. Thanks:)

+7
linux ubuntu mv xargs
source share
3 answers

If you use find , I would recommend that you use the -exec attribute. So your result should be find . -name "*.jpg" -exec mv {} /home/new/location \; find . -name "*.jpg" -exec mv {} /home/new/location \; .

However, I would recommend checking that the find command returns by replacing the exec part with: -exec ls -lrt {} \;

+13
source share

You could try:

  for f in *.jpg do; mv -tv $f /var/www/html/ done for f in *.png do; mv -tv $f /var/www/html/ done for f in *.bmp do; mv -tv $f /var/www/html/ done 

you should also carefully read xargs (1) ; I strongly suspect that

  find . -name "*.jpg" -print0 | xargs -n 1000 -I '{}' mv '{}' ../ 

should work for you

Finally, learn more about rename (1) . This is probably enough for the job.

+2
source share

Try:

 find /path/to/old-directory -type f | xargs -i mv "{}" /path/to/new-directory 
+1
source share

All Articles