HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
System Administration
Showing results for 
Search instead for 
Did you mean: 

mv command and sub directories

Mike Loring
Occasional Visitor

mv command and sub directories

I want to move all files ending in .jpg on the root dirve to a directory called photos. Can I use mv -r /root *.jpg ~photos or something like that which is recursive and looks for .jpg files in all sub directores of the volume?

Re: mv command and sub directories

find / -name "*.jpg" -exec mv {} ~/photos \;

(Unfortunately you can't use +, unless you write a script to do the mv and reverse the args.)
Ganesan R
Honored Contributor

Re: mv command and sub directories

Hi Mike,

In addition to Dennis reply,

If you want to search and move only from root filesystem and do not cross other mount points use this,

#find / -xdev -name "*.jpg" -exec mv {} ~/photos \;

Question for Dennis,

#find / -xdev -name "*.jpg" -exec mv {} ~/photos +

won't this work? unfortunately not near to the system to test it..
Best wishes,


Re: mv command and sub directories

>Ganesan: find / -xdev -name "*.jpg" -exec mv {} ~/photos +
>won't this work?

I tried those before replying. Neither find + nor xargs works with multiple arguments inserted other than the end.
In fact find(1) says everything from the "{}" to the "+" is replaced.

So you are left with writing a script, if you want performance:
find / -xdev -name "*.jpg" -exec move_them ~/photos {} +
mv "$@" "$TARGET"