+ Post New Thread
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
Scripts Thread, bash script doesnt like folders with spaces in Coding and Web Development; Code: roberts Photos # find . -type f -name "*.jpg" -exec mv {} /tmp \; roberts Photos # ls /tmp ...
  1. #16

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,531
    Thank Post
    1,341
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    Code:
    roberts Photos # find . -type f -name "*.jpg" -exec mv {} /tmp  \;
    roberts Photos # ls /tmp
    1.jpg  2.jpg  holiday.jpg
    Yep. Thanks.

    So, does this mean that I cant use /Photos/new as the destination to move photos from /Photos/new/blah blah ?

  2. #17

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,866
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Quote Originally Posted by RabbieBurns View Post
    Im not quite sure what this error means?

    Code:
    roberts Photos # find . -name *.jpg -type f -print0 | xargs -0 mv '{}' /Photos/new
    mv: target `./new/Summer 2009/summer2.jpg' is not a directory
    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 12:23 PM.

  3. 2 Thanks to powdarrmonkey:

    CyberNerd (12th February 2009), RabbieBurns (12th February 2009)

  4. #18


    Join Date
    Jan 2006
    Posts
    8,202
    Thank Post
    442
    Thanked 1,032 Times in 812 Posts
    Rep Power
    339
    Quote Originally Posted by powdarrmonkey View Post
    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.
    Thats useful to know, I never quite got the hang of xargs but will endeavor to learn!

  5. #19

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,531
    Thank Post
    1,341
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    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]
    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]
    I appreciate your help. (PS. The file 2.jpg is in /Photos/, which is where Im running the command)

  6. #20

    powdarrmonkey's Avatar
    Join Date
    Feb 2008
    Location
    Alcester, Warwickshire
    Posts
    4,866
    Thank Post
    412
    Thanked 777 Times in 650 Posts
    Rep Power
    182
    Damn, it's really not going well for me today Wrap 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
    Code:
    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
    into
    Code:
    mv 1.jpg 2.jpg 3.jpg 4.jpg 5.jpg 6.jpg 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).

  7. Thanks to powdarrmonkey from:

    RabbieBurns (12th February 2009)

  8. #21

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,531
    Thank Post
    1,341
    Thanked 470 Times in 307 Posts
    Blog Entries
    6
    Rep Power
    200
    Thats it!

    Works well. Many thanks



SHARE:
+ Post New Thread
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Script to share multiple folders
    By originofsymmetry in forum Scripts
    Replies: 8
    Last Post: 26th August 2008, 12:11 AM
  2. Script to delete specific folders
    By Baasha_Bhai in forum Scripts
    Replies: 8
    Last Post: 2nd July 2008, 11:41 AM
  3. VB script to delete certain folders
    By PTD in forum Scripts
    Replies: 7
    Last Post: 4th June 2008, 01:30 PM
  4. Script to delete certain folders
    By Pumaedition in forum Scripts
    Replies: 4
    Last Post: 22nd April 2008, 11:08 PM
  5. VB Script to create folders
    By markesmith in forum Scripts
    Replies: 2
    Last Post: 26th April 2007, 04:03 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •