Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ShinyToy

macrumors newbie
Original poster
Jan 16, 2008
21
0
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?
 
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.
 
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.
 
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.

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).
 
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.
 
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.

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
 
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
 
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.
 
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.


Except this syntax is incorrect. mv is missing a parameter. ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.