Yep. Thanks.Code:roberts Photos # find . -type f -name "*.jpg" -exec mv {} /tmp \; roberts Photos # ls /tmp 1.jpg 2.jpg holiday.jpg
So, does this mean that I cant use /Photos/new as the destination to move photos from /Photos/new/blah blah ?

Yep. Thanks.Code:roberts Photos # find . -type f -name "*.jpg" -exec mv {} /tmp \; roberts Photos # ls /tmp 1.jpg 2.jpg holiday.jpg
So, does this mean that I cant use /Photos/new as the destination to move photos from /Photos/new/blah blah ?

Sorry, my mistake. It should read:
Code:find . -name *.jpg -type f -print0 | xargs -0 --replace mv '{}' /Photos/new
As an aside, using find with -exec results in one forked process per file processed, wheras using xargs puts as many files as possible into one call to mv, so one forked process per many, many files. If you're moving lots of things around, you'll probably notice the difference.
Edit: another thought, you can also use -i instead of --replace in your call to xargs.
Last edited by powdarrmonkey; 12th February 2009 at 11:23 AM.
CyberNerd (12th February 2009), RabbieBurns (12th February 2009)


Code:roberts Photos # find . -name *.jpg -type f -print0 | xargs -0 --replace mv '{}' /Photos/new find: paths must precede expression: 2.jpg Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]I appreciate your help. (PS. The file 2.jpg is in /Photos/, which is where Im running the command)Code:roberts Photos # find . -name *.jpg -type f -print0 | xargs -0 -i mv '{}' /Photos/new find: paths must precede expression: 2.jpg Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

Damn, it's really not going well for me todayWrap your *.jpg in quotes to stop bash interpreting it, like "*.jpg". Otherwise, bash tries to give find a list of files that it think it should be finding, and find gets grumpy.
@Cybernerd: All it does it turn
intoCode:mv 1.jpg /tmp mv 2.jpg /tmp mv 3.jpg /tmp mv 4.jpg /tmp mv 5.jpg /tmp mv 6.jpg /tmp mv 7.jpg /tmp
but also does some sanity checking, like making sure that the list of arguments isn't so long as to cause a buffer overflow (in which case, splits it into two calls).Code:mv 1.jpg 2.jpg 3.jpg 4.jpg 5.jpg 6.jpg 7.jpg /tmp
RabbieBurns (12th February 2009)

Thats it!
Works well. Many thanks![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)