How do I move 999 files quickly?

Discussion in 'macOS' started by ShinyToy, Nov 18, 2008.

  1. ShinyToy macrumors newbie

    Joined:
    Jan 16, 2008
    #1
    I've got a folder with several thousand jpegs in it. I need to move 999 of them to another folder. I have the name of each file (the full directory listing actually) I need to move in a text file.

    I couldn't figure out how to enter in the file names to automator and I can't figure out how to use the terminal mv command with many files.

    Does anyone have any suggestions?
     
  2. belvdr macrumors 601

    Joined:
    Aug 15, 2005
    #2
    Well, let's say the filenames are in a file called pictures_to_move.txt. In Terminal, you could:
    Code:
    for filename in `cat pictures_to_move.txt`; do mv $filename /path/to/new/folder; done
    where /path/to/new/folder is the path you want to move the files to.
     
  3. ShinyToy thread starter macrumors newbie

    Joined:
    Jan 16, 2008
    #3
    Thanks!

    I'm almost there... Sorry, I'm totally new to using terminal.

    It doesn't move them when I do that. Instead it spits out this a bunch of times:

    usage: mv [-f | -i | -n] [-v] source target
    mv [-f | -i | -n] [-v] source ... directory


    What does it mean? I looked up "man mv" and it says that it's about whether to overwrite files or not but I'm not sure what the syntax should be.
     
  4. Mindflux macrumors 68000

    Mindflux

    Joined:
    Oct 20, 2007
    Location:
    Austin
    #4
    Are you using the correct syntax punctuation? Those tick marks aren't your normal quotes, they are the ones on the tilde key (next to the 1 key).
     
  5. ShinyToy thread starter macrumors newbie

    Joined:
    Jan 16, 2008
    #5
    Yeah, those are the ones I'm using.

    Here's what I typed in:


    for filename in `cat corrupted_photos2.txt`; do mv /corrupted_photos; done


    That seems right, yeah? The above file and folder are in my home directory so the path is just as above I think.
     
  6. Dark Dragoon macrumors 6502a

    Dark Dragoon

    Joined:
    Jul 28, 2006
    Location:
    UK
    #6
    You're missing the $filename

    instead of:
    Code:
    for filename in `cat corrupted_photos2.txt`; do mv /corrupted_photos; done
    it should be:
    Code:
    for filename in `cat pictures_to_move.txt`; do mv $filename /corrupted_photos; done
     
  7. ShinyToy thread starter macrumors newbie

    Joined:
    Jan 16, 2008
    #7
    Of course! Thankyou.

    But now there seems to be a problem...

    I've done that and it took them out of the original folder. But they're not in the new one now... And they don't seem to be anywhere.

    It's not a disaster if they're gone because I backed them up. When I do a spotlight search they don't turn up anywhere now.

    Also, the command created a Unix Executable File called "corrupted_photos" which is 2mb in size.

    Have I deleted the files somehow???

    By the way, just in case there was something wrong with my command, here's what I entered:

    for filename in `cat corrupted_photos2.txt`; do mv $filename /corrupted_photos; done
     
  8. 3247 macrumors regular

    Joined:
    Feb 9, 2008
    Location:
    Germany
    #8
    Well, you ran 'mv' several times. Each time, 'mv' moved one file to '/corrupted_photos', overwriting the previous one. In other words, you lost every file except the last one (just rename 'corrupted_photos' to 'whatever.jpeg').

    '/corrupted_photos' should have been an existing folder. Otherwise, 'mv' assumes you want a file with that name.

    To avoid that in the future, you could write:
    Code:
    for filename in `cat pictures_to_move.txt`; do mv $filename /corrupted_photos[B]/[/B]; done
    The trailing slash tells 'mv' that you want to move the file to a folder. It would then print an error message if the folder does not exist instead of overwriting the file each time.

    Even better, you could just do it with a single 'mv':
    Code:
    (cat pictures_to_move.txt; echo '/corrupted_photos')|xargs mv -n
    Instead of running 'mv' once for every file as 'for' does, 'xargs' runs it once all files.
    -n tells 'mv' not to overwrite files.
     
  9. Mindflux macrumors 68000

    Mindflux

    Joined:
    Oct 20, 2007
    Location:
    Austin
    #9

    Except this syntax is incorrect. mv is missing a parameter. ;)
     
  10. ShinyToy thread starter macrumors newbie

    Joined:
    Jan 16, 2008
    #10
    Ok. Thanks. Luckily I backed it up. I'll try it again and report back.
     
  11. 3247 macrumors regular

    Joined:
    Feb 9, 2008
    Location:
    Germany
    #11
    No, xargs adds all the parameters.
     
  12. Mindflux macrumors 68000

    Mindflux

    Joined:
    Oct 20, 2007
    Location:
    Austin
    #12
    No, it's decidedly missing something. did you try it yourself? ;)
     

Share This Page