Saturday, April 27, 2024
 Popular · Latest · Hot · Upcoming
37
rated 0 times [  37] [ 0]  / answers: 1 / hits: 154854  / 3 Years ago, wed, june 9, 2021, 4:37:45

How can I copy files or directories from one user to another user on the same machine via the commandline?


Suppose there is a file test.txt in the home directory of USER1. I need to copy that file to the home directory of USER2 on my machine. How can I do it via the commandline?


More From » users

 Answers
0

Assuming that you have sudo privileges the following command will do.



sudo cp /home/USER1/FNAME /home/USER2/FNAME && sudo chown USER2:USER2 /home/USER2/FNAME


Will copy the file from USER1 to USER2, and then change the owner of the copy in /home/USER2 to USER2



If you do not have sudo privileges, then the two users will need to ensure that you have read permissions on the USER1 directory, and write access on the USER2 directory. If you have these accesses, you can enter the command:



cp /home/USER1/FNAME /home/USER2/FNAME


This will copy the file in question, but USER2 may not be able to manipulate the file until they have appropriate permissions.


[#22346] Friday, June 11, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
unsmmoth

Total Points: 72
Total Questions: 113
Total Answers: 95

Location: Thailand
Member since Tue, Oct 6, 2020
4 Years ago
;