I don't get a prompt to overwrite. Why not?
Because you're supposed to know what you're doing. Especially as root, you can overwrite pretty much anything, so pay attention to that.
Use the -i
option for cp
to get a prompt before overwriting existing files. If you always want to be reminded of this, consider creating an alias for cp
to cp -i
.
The permissions are unchanged. But if […] file someFile
does not exist it is owned by root
and not user
. Why?
Because the file you're copying to is already existing. It's not deleted and re-written. It's still owned by user
.
However, check cp
's -p
option. It will preserve the attributes of the source file, namely the mode, ownership and timestamps. Otherwise, the mode and ownership attributes of the target file will stay (except for the timestamps which will indicate a modification).
If there's no target file, obviously the attributes of the source file need to be copied, since they can't be inherited from a target file. You'll basically just create a new file, and in this case it's owned by root
.
5Just a comment on using aliases adding
-i
tocp
/rm
: it can be a problem if one gets used to this, and suddenly finds oneself on a system where these non-standard aliases are not set. It is good to not make a habit out of expecting them. "Default is almost always better", as I apparently said just now :-) . – Daniel Andersson – 2012-04-06T09:01:18.243Absolutely. If you're root you should be aware of that and it's not the first time I've seen someone overwrite important system files being too eager while copying. – slhck – 2012-04-06T09:14:37.860