LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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

Reply
 
Search this Thread
Old 03-20-2006, 06:31 PM   #1
keysorsoze
Member
 
Registered: Apr 2004
Location: Queens, NY
Distribution: Red Hat, Solaris
Posts: 295

Rep: Reputation: 30
Restoring Permissions


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.

Thanks.
 
Old 03-20-2006, 06:57 PM   #2
mjmwired
Member
 
Registered: Apr 2004
Distribution: CentOS6, CentOS5, F16, F15, Ubuntu, OpenSuse
Posts: 620

Rep: Reputation: 39
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
In the future use 'tar' to backup.
 
Old 03-20-2006, 06:58 PM   #3
Electro
Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
You should have used cp -a source destintation. It preserves the permissions, ownership, and group of all files.
 
Old 03-20-2006, 07:47 PM   #4
keysorsoze
Member
 
Registered: Apr 2004
Location: Queens, NY
Distribution: Red Hat, Solaris
Posts: 295

Original Poster
Rep: Reputation: 30
Thanks.

Hi! Thanks for the reply I give your script a try. Hopefully it works and next time I'll use the cp -a Thanks A lot guys.
 
Old 03-20-2006, 08:02 PM   #5
keysorsoze
Member
 
Registered: Apr 2004
Location: Queens, NY
Distribution: Red Hat, Solaris
Posts: 295

Original Poster
Rep: Reputation: 30
Hi! mjmwired,

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

What am I doing wrong with the script. Thanks.
 
Old 03-20-2006, 08:19 PM   #6
mjmwired
Member
 
Registered: Apr 2004
Distribution: CentOS6, CentOS5, F16, F15, Ubuntu, OpenSuse
Posts: 620

Rep: Reputation: 39
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.
 
Old 03-20-2006, 09:06 PM   #7
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
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

Last edited by mikshaw; 03-20-2006 at 09:07 PM.
 
Old 03-20-2006, 09:24 PM   #8
keysorsoze
Member
 
Registered: Apr 2004
Location: Queens, NY
Distribution: Red Hat, Solaris
Posts: 295

Original Poster
Rep: Reputation: 30
Thanks.

Thanks for the help guys I'll give it a shot.
 
Old 05-16-2008, 12:42 PM   #9
nala
LQ Newbie
 
Registered: May 2008
Posts: 1

Rep: Reputation: 0
Thumbs up Replace the * with . to change the user's dir as well

Example:

#!/bin/sh
for u in `ls /test`
do
chown $u:GID -R /test/$u/.
done


Replace /test with /home or wherever other folder you want updated.

Replace GID with a group GID from your system (check /etc/group for local groups).

I HIGHLY suggest you test this first. Also just realized this thread is 4 years old.

Last edited by nala; 05-16-2008 at 12:43 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accidentally changed the permissions of /proc/, help restoring them please Th3James Linux - General 5 01-24-2006 03:24 AM
restoring default device ownerships/permissions under_r_run Linux - Newbie 5 07-27-2005 01:27 PM
Need help restoring /var permissions Thiink Slackware 1 02-21-2005 05:36 AM
Help restoring file permissions from a Dump bminish Linux - Newbie 3 12-12-2004 01:34 PM
restoring mysql databases? and mysql permissions... armegeden Linux - Software 0 03-13-2003 11:04 AM


All times are GMT -5. The time now is 01:46 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration