If I do a sudo cp /etc/foo.txt ~/foo.txt, the new file is created with root as the owner.Right now, I see no way around this other than using the last two commands (ls to clarify use-case):belmin@server1$ ls /etc/foo.txt>  -rw------- 1 root root 3848 Mar  6 20:35 /etc/foo.txt>belmin@server1$ sudo cp /etc/foo.txt ~/foo.txtbelmin@server1$ sudo chown belmin: $_I would prefer:Doing it in one sudo command.Not having to specify my current user (maybe using a variable?).
Is there a way to tell sudo to set my username as owner for the files created instead of root?
bash;files;sudo
Use install instead of cp:sudo install -o belmin /etc/foo.txt ~/foo.txt