I would like to copy files and folders recursively from an external drive to my internal SSD.
However, when I drag and drop, and, subsequently, when I use the copied files, I am always asked to enter an administrator credentials. I don't know if it is a chmod
or chown
issue, or both (difficulties to making the difference between them).
Is there a way (through Terminal I guess) to copy the files:
- while preserving all the files and folders details (i.e. original date/time stamps and whatever metadata necessary/useful);
- but gaining ownership (so I don't have to enter administrator credentials each time I want to look, modify or move a file).
I guess it is either cp
or rsync
, but I must admit having difficulties sorting out and understanding all the available switches.
Best Answer
In order to successfully copy the files in the first place, you need at least have read access to the files at the original location.
To make sure that you can read them, you can either change their permissions with
sudo chmod -R o+rx /drag/your/original/folder/from/Finder/here
or as suggested in the comments of your question have ownership of the drive ignored for the time-being, which leaves the original files unchanged.To actually copy the files over, use the following command:
For more information during the copy process, use the following command:
Mind the slash at the end of the target folder or the target folder itself will be overwritten by the contents.
Understanding permissions when moving/copying files in UNIX/BSD (Mac OS X's underlying system is based on BSD):
A
toB
on the same partition/volume, the ownership of the files will not changeA
toB
between different partitions/volumes, the ownership of the files will change to the user moving them (applyingsudo
to the copy command will have the target files ownership set toroot
)A
toB
regardless of the location will apply the ownership of the target files to the user copying them (applyingsudo
to the copy command will have the target files ownership set toroot
)With number 1 only the file descriptors will change internally, but no file will be physically moved. With 2 and 3 the files are physically copied over to the new location with step 2 doing a second step and deleting them from the original location after each copy.
UPDATE (to address comment):
If you copied over the files using
sudo
, you can modify the permissions of the target files usingchown
andchmod
.Commands are:
<user>
is the account name of your user (not the full name):group
is a group, which by default for any user isstaff
and for any admin isadmin
. Since it is not required, you can omit to leave it as is (hence the square brackets)This will give you and the primary group r/w and execution/traversal rights on the files.