Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-17-2014, 02:02 AM   #1
byran cheung
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
Senior Member
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,388

Rep: Reputation: 851Reputation: 851Reputation: 851Reputation: 851Reputation: 851Reputation: 851Reputation: 851

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

man chown

       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

              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)

              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
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:

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

To change owner of all the files and directories recursively:
chown -R mary *
Old 12-17-2014, 02:23 AM   #4
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
Registered: Oct 2011
Location: Nepal
Distribution: RHEL, CentOS, Slackware
Posts: 129
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:	5
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
Registered: Jan 2009
Location: SE USA
Distribution: Mageia 4 formerly PCLOS
Posts: 144
Blog Entries: 5

Rep: Reputation: 20
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??


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 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

All times are GMT -5. The time now is 04:09 PM.

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