Become a MacRumors Supporter for $25/year with no ads, private forums, and more!

unix command to copy all files in a dir to another dir

maya90

macrumors member
Original poster
Feb 16, 2011
58
3
I'm copying LOTS (6,000+) photos from iPhone to computer...

since my MacBook Pro is so old it doesn't read my iPhone, I have borrowed someone else's...

and had to copy all photos to a file in the computer, couldn't copy directly to a memory stick I had connected thru USB... (it took too long..)

now when I attempt to copy photos from this dir in computer to my memory stick, Finder get stuck in "preparing to copy" (either that or it takes way way too long..)

I think I will have to do this in the terminal...

here,
https://forums.macrumors.com/threads/preparing-to-copy-can-this-be-turned-off.893133/

it says this is unix command to copy all files from a dir to another dir:

"cp -R <source> <target>"

is this correct?

thank you...
 

maya90

macrumors member
Original poster
Feb 16, 2011
58
3
in my friend's computer, you don't see full path to dirs like you can see my own computer (at very top of finder window..)

so how do I find, in my friend's computer, the exact path to: 1) file I created in his "Documents" dir., and 2) to folder I created in my memory stick where I want to copy photos to? (I did some tests in my own computer with this command:

cp -a /source/. /dest/

and it works perfectly...)

thank you very much..
 
Last edited:
Comment

maya90

macrumors member
Original poster
Feb 16, 2011
58
3
this command works fine in my computer.. in my friend's computer however, unix responded:

usage: cp [-R [-H | <...........> source_file target_file
cp [-R [-H | <...........> source_file ... target director


what do I need to do, please....
 
Comment

maya90

macrumors member
Original poster
Feb 16, 2011
58
3
hi.... thank you for your response...

I did:
cp -R /source/. /dest/


got EXACT SAME response,

usage: cp [-R [-H | <...........> source_file target_file
cp [-R [-H | <...........> source_file ... target director


& of course it did not copy the files..

man, this is driving me nuts.. why do these commands work in my own computer and not in the other one?

thank you..
 
Comment

Loki.Mephisto

macrumors 6502a
I believe your error is in the leading "/" - this tells the OS to look at root level.

Say you have a directory in your folder called source_dir "/Users/youruser/Documents/source_dir" and want to copy it to your USB drive mounted as "/Volumes/YourUSBDrive"

In this scenario, you could copy the directory source_dir using "cp -R /Users/youruser/Documents/source_dir /Volumes/YourUSBDrive" or, from within your Documents folder: "cp -R source_dir /Volumes/YourUSBDrive" (notice the missing slash before source_dir in the second command)

Key here is to notice that leading "/" means on root level; so the command you issued was looking for your source on root level. Not sure if this was intended.
So, for example, if you issued "cp -R /source_dir /Volumes/YourUSBDrive" (notice the leading slash here, as opposed to the command issued earlier) from within your Documents folder, the system would have looked for a volume called "/source_dir" which is unlikely to exist and would not be the directory you intended to copy in the first place
 
Last edited:
Comment

maya90

macrumors member
Original poster
Feb 16, 2011
58
3
I believe your error is in the leading "/" - this tells the OS to look at root level.

Say you have a directory in your folder called source "/Users/youruser/Documents/source_dir" and want to copy it to your USB drive mounted as "/Volumes/YourUSBDrive"

In this scenario, you could copy the directory source using "cp -R /Users/youruser/Documents/source_dir /Volumes/YourUSBDrive" or, from within your Documents folder: "cp -R source_dir /Volumes/YourUSBDrive" (notice the missing slash before source_dir in the second command)

Key here is to notice that leading "/" means on root level; so the command you issued was looking for your source on root level. Not sure if this was intended.
So, for example, if you issued "cp -R /source_dir /Volumes/YourUSBDrive" from within your Documents folder, the system would have looked for a volume called "/source_dir" which is unlikely to exist and would not be the directory you intended to copy in the first place
 
Comment

maya90

macrumors member
Original poster
Feb 16, 2011
58
3
remember, this works fine in my own computer....

ok, so error is in leading "/" ? in both source & target?

I tried taking it out of source and target, it didn't work...
it said, "user/........ is not a dir, etc...

again, remember, this works FINE in my own computer, only in my friend's computer none of these commands work..

thank you for your help..

(PS: in my friend's computer I copied paths from get-info window, I'm pretty sure they're correct..)
 
Comment

chown33

Moderator
Staff member
Aug 9, 2009
8,881
5,338
vertical
You probably need to post exactly what was typed or entered into the Terminal window. Not an approximation of it.

Please post the complete exact command line, including the complete text of any error message that it produces. Use copy and paste, rather than retyping into a post.

Details are important. Since you're not posting the exact details, all we can do is guess at where the problem really is.
 
Comment

Loki.Mephisto

macrumors 6502a
Well, it depends: As said, leading slashes means on root level, i.e. the upper most level within the file system.

You could use trailing slashes, but keep in mind: if you use trailing slashes, you have to use the full path.

To use the above example: if you are in the user's Documents directory, you could address a folder within either by using the full path using leading slash like so:

cp - R /Users/YourUser/Documents/source_dir

or by referencing mentioned directory relative to the directory you are in right now like so:

cp -R source_dir

If you'd issue cp -R /source_dir in the latter sample this would be an error, since the operating system would look for source_dir on root file system level rather than relative to your current directory.
 
Comment

maya90

macrumors member
Original poster
Feb 16, 2011
58
3
ok, here it is EXACTLY how I typed in my friend's machine.... (if I use '-A' I get exact same msg..)

MacBook-Pro-de-Marco:~ marcovallarinosulzer$ cp -R /Users/marcovallarinosulzer/Documents/photos_coca/. /Volumes/32 GB/photos_iph6

usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file

cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory




(this is how I tried to do it in my friend's machine... I copied from terminal window, emailed it to myself, and pasted here from my incoming email..)

again, this command, (& also with -a & -A) works fine in my own computer (w/different paths, of course...)

thank you very much for your help...
 
Last edited:
Comment

chrfr

macrumors G4
Jul 11, 2009
10,185
3,897
(this is how I tried to do it in my friend's machine... I copied from terminal window, emailed it to myself, and pasted here from my incoming email..)

again, this command, (& also with -a & -A) works fine in my own computer (w/different paths, of course...)

thank you very much for your help...
Posting what worked on your friend's computer doesn't help us help you if the command you're typing isn't working on your computer. What command did you try to use on your computer?
 
  • Like
Reactions: millerj123
Comment

maya90

macrumors member
Original poster
Feb 16, 2011
58
3
no, it's the other way around...

this command is working fine in my own computer, but NOT IN HIS.....;~)))

so far have not gotten this command to work in my friend's computer at all...

again, this is from my friend's machine:

MacBook-Pro-de-Marco:~ marcovallarinosulzer$ cp -R /Users/marcovallarinosulzer/Documents/photos_coca/. /Volumes/32 GB/photos_iph6

usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory



thank you....
 
Last edited:
Comment

chrfr

macrumors G4
Jul 11, 2009
10,185
3,897
no, it's the other way around...

this command is working fine in my own computer, but NOT IN HIS.....;~)))

so far have not gotten this command to work in my friend's computer at all...

thank you....
As an alternative to the above suggestion, type cp -R followed by a space in terminal, then drag the folder that contains the files you're trying to copy. Then enter the path where you want the files to go.
 
Comment

DeltaMac

macrumors G4
Jul 30, 2003
10,671
2,889
Delaware
I think the /32 GB/ volume name is probably where you are mis-typing the command (and may be why it WORKS on one Mac but not another Mac). You are likely forgetting that spaces need to be handled differently in file paths.
To expand on what chrfr posted:
Type cp -R followed by a space in the terminal, then drag the folder, that contains the files you're trying to copy, your terminal window. You should see the exact path show up in the terminal.
Now, same thing with the destination folder. Drag THAT folder to your terminal window. You again should see the exact path appear (correctly this time). You will see that terminal added an escape backslash to the space. This is the correct method to use a space in a file name, unless you choose to enclose the file or folder name in quotes. Much simpler to let the terminal do that for you by dragging the folder into your terminal window (and it will be spelled correctly, too!)
And, press enter to start the copy. Should work this time.
 
Comment

maya90

macrumors member
Original poster
Feb 16, 2011
58
3
As an alternative to the above suggestion, type cp -R followed by a space in terminal, then drag the folder that contains the files you're trying to copy. Then enter the path where you want the files to go.

hi.. that didn't work.. got exact same response... this is comment I typed in this time:

MacBook-Pro-de-Marco:~ marcovallarinosulzer$ cp -R /Users/marcovallarinosulzer/Documents/photos_coca /Volumes/32 GB/photos_iph6

(dragged source dir into terminal window, like you suggested..)

again: got this:

usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory


(looks to me like this is a problem with the command, not the paths..)

oh brother I don't get this.. so there are different versions of unix in both computers, or WHAT???

again, thank you for your response.....
 
Comment

maya90

macrumors member
Original poster
Feb 16, 2011
58
3
oh man.... I got it!!!

in memory stick (target) there was a SPACE in the path (I had named it "32 GB".. so I renamed it to "32GB" and violà...
(it worked in my computer b/c I was testing with a diff memory stick, which of course was named correctly...)

it's just that b/c of the msg I was getting back from unix I didn't realize the problem was with the path to the target dir..

thank you all very much for your help... I do appreciate it....

(it's still copying.. it's taking a while (it's over 6,000 photos...) but I think it will be ok...
 
Comment

chown33

Moderator
Staff member
Aug 9, 2009
8,881
5,338
vertical
Yes, spaces need to be quoted or escaped.

If you had made the destination dir in Finder, you could have dragged that onto the Terminal window and dropped it, and it would have expanded to the escaped version. Specifically, there would be a backslash before the space.

DeltaMac mentioned the backslash in post #17.


The error message came out the way it did because you passed in 3 values to the cp command. The 3rd value was "GB/photos_iph6", and if the dir "GB" didn't already exist in your working directory, then 'cp' can't create it.

There also wouldn't be a file or dir named "/Volumes/32", so that path doesn't exist either.
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.