LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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, 03: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, 03:14 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,166

Rep: Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751
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, 03: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, 03:23 AM   #4
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,307
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, 05:56 AM   #5
metalaarif
Member
 
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 06:02 AM.
 
Old 12-19-2014, 04:14 PM   #6
XenaneX
Member
 
Registered: Jan 2009
Location: SE USA
Distribution: Mageia 4 formerly PCLOS
Posts: 144
Blog Entries: 5

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


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


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