LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 12-17-2014, 02:02 AM   #1
byran cheung
Member
 
Registered: Sep 2013
Posts: 321

Rep: Reputation: Disabled
change file owner to another owner


In a directory , there are many files , the file owner are different , could advise if I want to change a specific owner ( eg. peter ) to another owner ( eg. mary ) ( do not change all file owner , just change peter to mary ) , what can I do ? thanks
 
Old 12-17-2014, 02:14 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,481

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Seriously??

Do you actually bother to look at ANYTHING? Or is your first action to post on here??

Code:
man chown

OPTIONS
       Change  the  owner and/or group of each FILE to OWNER and/or GROUP.  With --reference, change the owner and group of each FILE to those
       of RFILE.

       -c, --changes
              like verbose but report only when a change is made

       --dereference
              affect the referent of each symbolic link, rather than the symbolic link itself (this is the default)

       -h, --no-dereference
              affect each symbolic link instead of any referenced file (useful only on systems that can change the ownership of a symlink)

       --from=CURRENT_OWNER:CURRENT_GROUP
              change the owner and/or group of each file only if its current owner and/or group match those specified  here.   Either  may  be
              omitted, in which case a match is not required for the omitted attribute.
It's the THIRD option described!
 
Old 12-17-2014, 02:22 AM   #3
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
In Linux a file or a directory has following owners: "user", "group" and "other"

first to know owner do:

ls -l filename
or ls -l
to see all the files and directories in current directory.

Command to change:

user:
chown mary filename

user + group:
chown mary:mary filename

To change all files and directories with owner peter to mary:

for i in `ls -l -G | grep "peter" | awk '{print $8}'`; do
chown mary $i
done

To change owner of all the files and directories recursively:
chown -R mary *
 
Old 12-17-2014, 02:23 AM   #4
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Chown supports a "from X" -> "To Y" logical test.

chown --from=Peter Mary /path/to/target
 
Old 12-17-2014, 04:56 AM   #5
metalaarif
Member
 
Registered: Oct 2011
Location: Nepal
Distribution: RHEL, CentOS, Slackware
Posts: 131
Blog Entries: 1

Rep: Reputation: 3
Like others said, it should work right away.

Just to make it easy and lets assume you want to change owner within /home directory

$ cd /home
$ ls -lh [here you should see the owner and group]
$ chown mary:mary filename [remember we're changing but owner and group to mary]
$ ls -lh [confirm, if it worked or not]

check the screenshot just incase
Attached Thumbnails
Click image for larger version

Name:	Screenshot.png
Views:	21
Size:	44.7 KB
ID:	17140  

Last edited by metalaarif; 12-17-2014 at 05:02 AM.
 
Old 12-19-2014, 03:14 PM   #6
XenaneX
Member
 
Registered: Jan 2009
Location: London
Distribution: MX16 & PCLOS
Posts: 181
Blog Entries: 5

Rep: Reputation: 22
Do you actually bother to look at ANYTHING? Or is your first action to post on here??

Do you actually bother to look at ANYTHING? Or is your first action to post on here??

Do you actually bother to look at ANYTHING? Or is your first action to post on here??
 
  


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
change file owner in a directory ust Linux - Newbie 1 12-11-2012 11:31 PM
Allow users other than the owner to change the mtime of a file groszdani Linux - General 1 09-08-2009 06:00 PM
Owner of a directory different than file owner problems Guardian-Mage Linux - Server 4 04-24-2009 10:26 AM
how to i change file owner back to root ? glacier1985 Linux - Newbie 10 06-17-2004 09:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:45 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