Issue
I want to create a new user in Linux, basically creating an exact copy of that user with all permission and access, read and write rights on all folders, subfolders and files (including hidden files).
It does not seem like an easy task. I am able to copy all files but I am not able to clone the rights for all files and subfolders.
What is the right procedure here?
- I first add the user
- Copy all files recursively for normal files
sudo cp -r /home/user1/* /home/user2/ && sudo chown user2:user2 /home/user2
- copy all files for hidden files
sudo cp -r /home/user1/.[^.]* /home/user2/ && sudo chown user2:user2 /home/user2
Transfer rights?
I really have no idea whether this is right
Solution
You want to recursively copy the whole user folder, not the contents. That automatically includes all "hidden" files. Afterwards you then change the ownership of the new folder:
cp -pPr /home/user1 /home/user2
chown -R user2 /home/user2
You really want to start reading the manual pages of the tools you use. They contain a wealth of precise information to explode: man cp
Answered By - arkascha Answer Checked By - Willingham (WPSolving Volunteer)