Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Hi! I recently backed up my home directory on my system with about 200 users using cp -rf /home /root. I recently had the entire old /home directory deleted. Now I issue the cp -rf /root/home /home command and it seems that all the files and directories now belong to the group root and owner group. Is there any way that I can restore ownership to respective owners without using chown on each directory.
You will have to 'chown' each directory, since your copying reset all ownership.
Just write a shell script that will recurse each home directory and based on the home directory name, reset all the ownership.
For example ONLY, something similar to the following... (be careful)
Code:
#!/bin/sh
for u in `ls /home`
do
chown $u:$u -R /home/$u/*
done
I tried your recursive script with no luck. Is it something I am doing wrong?
I simply named the script permiss and cut and paste your script above into it. I then gave it execute permissions and used sh permiss to execute it. However I get the following:
[root@localhost root]# sh permiss
chown: `ageraldo:ageraldo': invalid user
chown: `cvyas:cvyas': invalid group
chown: `dmartin01:dmartin01': invalid group
chown: `dsmith01:dsmith01': invalid group
chown: `ediaz:ediaz': invalid user
chown: `Ejanjua:Ejanjua': invalid user
chown: `fdiaz01:fdiaz01': invalid group
chown: failed to get attributes of `/home/gisrael/*': No such file or directory
chown: `goddo:goddo': invalid user
chown: `ianwar:ianwar': invalid group
chown: `mhernandez04:mhernandez04': invalid user
chown: failed to get attributes of `/home/obou/*': No such file or directory
chown: `rrosemin:rrosemin': invalid group
chown: `Sscott:Sscott': invalid user
That was just an idea, not a guaranteed solution. I made some assumptions:
I thought that each user had his own group.
I thought that each user's home directory was his his/her username.
What you require is something more complex. You will have to read in '/etc/passwd' and '/etc/group' and either write your own script or manually make the changes.
You could try using a period instead of a colon to separate user and group. If you have the typical "users" group you might try this modification of the script:
for u in `ls /home`
do
chown -R $u.users /home/$u/
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.