LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 05-22-2009, 01:32 PM   #1
tbeehler
Member
 
Registered: Aug 2003
Location: Washington State, USA
Distribution: Mainly RH 9.0
Posts: 227

Rep: Reputation: 30
Mass change ownership - slightly different.


Hello all,

I used a script to mass create some folders

/mnt/windows/foo
/mnt/windows/bar
etc x 100

on the folders, the folder ownership looks like

root.group
root.group
etc x 100

So, my question is, is there a way to say "whatever the folder name is, use that as the user name in chown"?

so it would grab the folder name "foo" and go:

chown foo.group foo/

and go on to the next folder name?

like find . -type d -exec chmod 755 {} \; only with chown?

It seems like it would be easy, but I'm having a tough time finding the syntax. Does anyone else know of a way to do this? Thanks in advance!
 
Old 05-23-2009, 01:29 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
My bad. I thought I knew what I was talking about. On review, it seems I'm badly mistaken, so I've deleted my remarks.

For anyone interested, I'd written:

for file in [/mnt/windows/foo,/mnt/windows/bar/ext\ x\ 100]
do
chown $basename $file
done

Note the excaped spaces in ext\ x\ 100 to prevent bash from parsing the path/filename as three seperate inputs to the for loop, withou comma delimiter.

The loop says basically to take the basename of the path and use that as the owner name input to the chown command.

Last edited by bigrigdriver; 05-23-2009 at 01:42 AM.
 
Old 05-23-2009, 02:09 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Code:
for dir in $(find . -type d)
do
  owner=${dir##*/}
  chown ${owner}:group $dir
done
Anyway, I guess that in your script at some point you already have the path and the name of the directory you're going to create, so that you can just add the chown statement immediately after mkdir.
 
Old 07-10-2009, 11:44 AM   #4
tbeehler
Member
 
Registered: Aug 2003
Location: Washington State, USA
Distribution: Mainly RH 9.0
Posts: 227

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by colucix View Post
Code:
for dir in $(find . -type d)
do
  owner=${dir##*/}
  chown ${owner}:group $dir
done
Anyway, I guess that in your script at some point you already have the path and the name of the directory you're going to create, so that you can just add the chown statement immediately after mkdir.
I forgot to reply to you, so I apologize for that, but your code worked perfectly! Thanks!
 
Old 07-10-2009, 01:24 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You're welcome!
 
  


Reply



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
Cannot change ownership jamaso Slackware 11 11-08-2010 11:01 AM
change device ownership ? thllgo Linux - Server 1 10-22-2007 05:10 PM
Change ownership apffal SUSE / openSUSE 1 11-09-2005 02:08 AM
unable to change ownership arjunjeyaprakash Linux - Newbie 12 09-06-2005 02:02 PM
change ownership Johng Linux - General 4 04-06-2004 02:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:19 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
Open Source Consulting | Domain Registration