LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-29-2012, 04:31 AM   #1
AngelDeaD
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Rep: Reputation: Disabled
chown all folder and subfolders in home with their own user


I have 52 directory in home folder, some files in those folders, are chown-ed to root.
I need script who chown folders and all files and folders in them to user named as folder in home.

If username john then there is folder in home named as john.

Last edited by AngelDeaD; 01-29-2012 at 04:33 AM.
 
Old 01-29-2012, 04:45 AM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 190Reputation: 190
script? use chown.
Specifically, chown -R

"man chown" for how to use chown.
 
Old 01-29-2012, 04:47 AM   #3
ophirg
Member
 
Registered: Jan 2008
Location: Israel
Distribution: Kubuntu 13.10
Posts: 134

Rep: Reputation: 34
use the "-R" flag. it's a very common flag in file related programs.
it applies the command recursively all the sub-directories.

Code:
chown -R john /home/john
 
Old 01-29-2012, 04:49 AM   #4
AngelDeaD
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by fukawi1 View Post
script? use chown.
Specifically, chown -R

"man chown" for how to use chown.
I want script. I want do it very very fast.
52 times type
chown -R username:username username
It's lil bit hard.
 
Old 01-29-2012, 04:56 AM   #5
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Code:
for dir in /home/*; do
  username=$(basename $dir)
  echo "changing ownership to $username in $dir"
  chown -R $username:$username $dir
done
 
1 members found this post helpful.
Old 01-29-2012, 04:58 AM   #6
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 190Reputation: 190
So you want to do it for every user? This wasn't clear in your original question.

Code:
/home # for i in *; do chown -R $i:$i /home/$i; done
should do it, although it will likely barf at the "lost+found" directory, if there is one..
 
1 members found this post helpful.
Old 01-29-2012, 05:23 AM   #7
AngelDeaD
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thank's everyone and sorry for my bad english explaining. It's not my native lang.
 
  


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
Change user's home folder mruda Linux - Newbie 1 11-23-2011 05:35 PM
Scripts to list folder contents and copy images from folder and subfolders brunces Linux - Newbie 6 11-03-2011 02:23 PM
Customized home folder for the every new user deepak_message Linux - General 2 07-08-2011 01:35 PM
How to chown of folder...ie-/home directory cbjhawks SUSE / openSUSE 2 12-21-2010 09:48 AM
I can not open the user folder in home and write in a shared folder jorge_ivan Linux - General 8 08-02-2006 12:28 PM


All times are GMT -5. The time now is 01:53 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration