No. No need for sudo with cp in this case.
If you use
to copy the file to the users home directory, the copy of the file will be owned by root, because
was running as root.
So after copying the file using
, you'd also have to use
sudo chown alex:alex ~/.xinitrc
in order to give the user ownership of the file.
Whereas if you use
on its own, without
Assuming the default 644 permissions are used on the file - the user has read access to the file. And as a normal user, read permissions are all you need in order to copy a file that is owned by root. And again, it will only succeed in copying the file if the destination the file is going to is a location that the user can
In other words, as long as the directory the user is writing the copied file to is either directly owned by them, or they have write permissions via group membership, or perhaps even the other/world permissions (e.g. Perhaps they're copying to a shared directory that is readable/writable by anybody).
As long as the destination the copied file is going to is a location that the user can
write to (e.g. /home/alex/.xinitrc), then the file will be copied. And the copy will be owned by the user.
If you try using
to copy a file owned by root to a location that is only writable by root, then
you'd definitely need
. Otherwise, it is NOT
So to sum up - without using
command is acting as a normal user AND
the user has read permissions on the original file AND
because the user has permission to write to the destination - then the original file (owned by root) will
be copied and the copied file will be owned by the user.
So as I originally recommended, simply use:
cp /etc/X11/xinit/xinitrc ~/.xinitrc