terminal commands for moving files

I am trying to move all of my raw photos from one drive to another. totally new to terminal. This is what I a typing and receiving. Can anyone help me decipher please?


jefferyhutchinson@Jefferys-iMac master catalogue cr2 and jpeg % find -iname '*.cr2' -exec cp {} /Volumes/14\ tb\ 1/ \;       


find: illegal option -- i


usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]


       find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]

iMac 27″ 5K, macOS 13.2

Posted on Mar 11, 2023 5:38 AM

Reply
Question marked as Top-ranking reply

Posted on Mar 12, 2023 4:03 PM

Compare the command that you entered above with this one:

find /Volumes/master\ catalogue\ cr2\ and\ jpeg -iname '*.cr2' -exec mv {} /Volumes/14\ tb\ 1\ /cr22/ \;


Above command is also using the code <> formatting here in the ASC forum. Here’s the button that inserts that:



There are two differences between the command you’ve tried (above), and this (corrected) command. One, the exec command should be -exec with the leading dash character, and second, the quote on the filename is an angled quote and not a vertical quote. The unterminated single quote (the angle quote doesn’t end the string) is why you got that quote> response, and how I knew a quoting error was lurking somewhere.


Before running the corrected command, I would suggest testing with the following (using slightly different syntax):

find "/Volumes/master catalogue cr2 and jpeg" -iname '*.cr2' -exec ls {} \;


Here’s the full and corrected command, using quoted strings on thenfile specification and not backslash escapes:


find "/Volumes/master catalogue cr2 and jpeg" -iname '*.cr2' -exec mv {} "/Volumes/14 tb 1 /cr22/" \;


And the prompts-interactively-for-each-move version, which I’ve used for testing:


find "/Volumes/master catalogue cr2 and jpeg" -iname '*.cr2' -exec mv -i {} "/Volumes/14 tb 1 /cr22/" \;


If the mv command is working as expected, quit the command (^C, etc) and re-specify the mv command without the -i.


In general… The shell wants vertical single quotes, and vertical double quotes, and GUI tools and this ASC forum text input box prefer to use the angled versions of these characters.


PS: The destination path with the training space on that intermediate directory looks wrong. You’ve shown it in your command, but I suspect that trailing space does not exist on that directory name. Which means using this:


find "/Volumes/master catalogue cr2 and jpeg" -iname '*.cr2' -exec mv {} "/Volumes/14 tb 1/cr22/" \;

Similar questions

20 replies
Question marked as Top-ranking reply

Mar 12, 2023 4:03 PM in response to terminalnewbie

Compare the command that you entered above with this one:

find /Volumes/master\ catalogue\ cr2\ and\ jpeg -iname '*.cr2' -exec mv {} /Volumes/14\ tb\ 1\ /cr22/ \;


Above command is also using the code <> formatting here in the ASC forum. Here’s the button that inserts that:



There are two differences between the command you’ve tried (above), and this (corrected) command. One, the exec command should be -exec with the leading dash character, and second, the quote on the filename is an angled quote and not a vertical quote. The unterminated single quote (the angle quote doesn’t end the string) is why you got that quote> response, and how I knew a quoting error was lurking somewhere.


Before running the corrected command, I would suggest testing with the following (using slightly different syntax):

find "/Volumes/master catalogue cr2 and jpeg" -iname '*.cr2' -exec ls {} \;


Here’s the full and corrected command, using quoted strings on thenfile specification and not backslash escapes:


find "/Volumes/master catalogue cr2 and jpeg" -iname '*.cr2' -exec mv {} "/Volumes/14 tb 1 /cr22/" \;


And the prompts-interactively-for-each-move version, which I’ve used for testing:


find "/Volumes/master catalogue cr2 and jpeg" -iname '*.cr2' -exec mv -i {} "/Volumes/14 tb 1 /cr22/" \;


If the mv command is working as expected, quit the command (^C, etc) and re-specify the mv command without the -i.


In general… The shell wants vertical single quotes, and vertical double quotes, and GUI tools and this ASC forum text input box prefer to use the angled versions of these characters.


PS: The destination path with the training space on that intermediate directory looks wrong. You’ve shown it in your command, but I suspect that trailing space does not exist on that directory name. Which means using this:


find "/Volumes/master catalogue cr2 and jpeg" -iname '*.cr2' -exec mv {} "/Volumes/14 tb 1/cr22/" \;

Mar 11, 2023 12:45 PM in response to terminalnewbie

Or, this might be faster than the UNIX find command by engaging 4 (arbitrary choice) processes for the copy. It is recursive so the choice of SRCDIR is important, and is case-insensitive (c):


/usr/bin/mdfind -onlyin SRCDIR 'kMDItemDisplayName == "*.cr2"c' | xargs -P 4 -I{} cp -a {} DESTDIR


Example (tested on macOS 13.2.1):


mdfind -onlyin ~/Documents/__WIP__/Images 'kMDItemDisplayName == "*.cr2"c' | xargs -P 4 -I{} cp -a {} ~/Desktop/E


With 500K files for potential processing, nothing will be overly quick.

Mar 12, 2023 4:56 PM in response to terminalnewbie

The command line is unforgiving. One wrong character, and all your data is gone. Not just those images, everything will be gone.


I strongly recommend that you DO NOT attempt to use the "mv" command. A lot can go wrong with that command. There is a very good chance that using "mv" in a script is functionally equivalent to running "rm".


You had it right the first time. Use the "cp" command. Then, when you have verified the results and the output is correct, you can manually delete the old files or do a similar find command to delete them.


Try the command without any -exec portion first. Verify it lists the files you want to operate on.


Then, add a test -exec, like so:


find </path/to/search> -iname '*.cr2' -exec echo cp {} /Volumes/14\ tb\ 1/ \; 


Verify that this works properly. You can do this by copying the first few lines and pasting them into the Terminal. Inspect the results. If they look good, then remove the "echo" part and run it for real.


When you are happy with the results, you can do something like this to clean up:


find </path/to/search> -iname '*.cr2' -delete

Mar 11, 2023 12:27 PM in response to terminalnewbie

Add additional Finder search criteria such as selecting a subset of files by years or such, then.


Or yes, zsh scripts will work fine for this stuff.


But I’d be looking for a photo management database package, at that scale.


You’re going to be creating one yourself one script at a time, otherwise.


If you do decide to continue with your own app design for your photo management app, I’d suggest having a look at Filemaker Pro as its underpinnings.


And FWIW, a mistake I’ve seen a number of photographers make: use and depend on the EXIF data and not the file system metadata. The file system metadata can change when you might not want it to. The EXIF data is more directly under your control (and that of your photo management app), and not under the control of the file system (which controls the file system metadata).

Mar 25, 2023 6:31 AM in response to MrHoffman

so, using the commands that you helped me with, I was able to move all of the CR2 files. Huge thanks for that. I changed the wildcard to jpeg and also changed the destination drive. kept the same source drive. Now I get an error


.Trashes: Permission denied


Am I correct in thinking that this refers to a hidden file on the external source drive? Any suggestions for how I fix it?

Mar 26, 2023 11:10 AM in response to terminalnewbie

That means a couple of areas of your storage were protected, and not searchable. Those two areas are among those normally protected, too. The command worked, but can’t report finding from those two areas.


There’s a way around that particular protection, but I’m hesitant to suggest using sudo on the find command here, as sudo is an override. An override that’s one mistake away from prodigious mayhem.

Mar 26, 2023 11:18 AM in response to terminalnewbie

terminalnewbie wrote:

I agree! I don't want to grant full disk access nor do I really want to use sudo. Not yet. I am just too green.

So, if I get those errors but Terminal does not return to the % prompt, should I just wait - is the command being run on the rest of the disk?


The find command will take as long as it takes. Spotlight runs in the background and caches the search results and the interactive part thus runs very quickly, while find runs at the speed of your storage and its contents. It’ll finish when it finishes.


There’s an mdfind command with a semi-obscurely-documented keyword syntax that runs at Spotlight speeds.

https://ss64.com/osx/mdfind.html

https://bryce-s.com/mdfind/

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

terminal commands for moving files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.