Operating System - HP-UX
1832279 Members
2208 Online
110041 Solutions
New Discussion

Re: Change ownership, chmod?

 
Andy Cole_1
Frequent Advisor

Change ownership, chmod?

Hi, i am new to Unix. And i am using HP UX. Would like to check how do i chaange the ownership from one user account to another user account if the files are scattered all over the system? Can i use one command to change from one owner to another owner? Example, all those files in the system that belongs to apple account, all changes to pear account? thanks
10 REPLIES 10
Geoff Wild
Honored Contributor

Re: Change ownership, chmod?

Actually, you want chown

find -user apple | xargs chown pear {};

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
RAC_1
Honored Contributor

Re: Change ownership, chmod?

Start by reading the man pages of chmod, chown and find commands.

What you are trying to do can be done with a single command. That would as follows.

find . -user apple -type f -exec chown pear {} \;
This would change the ownership of all files to pear. The following command would change the ownership of all directories to pear.

find . -user apple -type d -exec chown pear {} \;

Anil
There is no substitute to HARDWORK
Geoff Wild
Honored Contributor

Re: Change ownership, chmod?

oops...

should be:

find / -user apple | xargs chown pear {}

Rgds.....Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Andy Cole_1
Frequent Advisor

Re: Change ownership, chmod?

thanks for all your help.

So for the below command:

find / -user apple | xargs chown pear {}

Will it changes the directory ownership as well?

I would like to change the ownership of the directories and files. Would just one command be able to do all these? thanks
John Payne_2
Honored Contributor

Re: Change ownership, chmod?

Andy,

Do either of these to get files and directories, except in the find without the pipe to xargs, strip off the '-type' flag for the find command. It does entire heirarchy by default.

John

(You could just do a find '/ -user apple' to get the list first, if you want to verify...)
Spoon!!!!
Geoff Wild
Honored Contributor

Re: Change ownership, chmod?

Yes - that will do everything...

Just a thought - another option you have - is to delete user apple, then create user pear with apple's old uid.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Muthukumar_5
Honored Contributor

Re: Change ownership, chmod?

find command used to collect all files on the search path.

find / -user -type f "*"

will give all files who owner is there.

To change that permission to pear then,

find / -user apple -type f "*" -exec chown pear {} \;

If you want to change directory too then,

find / -user apple \( -type f -o type d \) -exec chown pear {} \;

HTH.
Easy to suggest when don't know about the problem!
Andy Cole_1
Frequent Advisor

Re: Change ownership, chmod?

Btw, is there any complication if i (the root) change the ownership of one account to another account (from apple account to orange account)?

Would the orange account be able to access all the files and directories that are previously from apple account?

What are the things to take note when changing of ownership? thanks
Geoff Wild
Honored Contributor

Re: Change ownership, chmod?

For your last question - no complications - only means that apple will no loger be the owner of the files - orange will have access to all the files owned by the previous user - apple.

Now, here's another tip - if apple and orange belong to the same group - say orchard, and the permissions on the file(s)/directory(s) are 664 or 775, then both apple and orange will have write access to the file(s)/directory(s).

Things to take note are - any scripts that say "su - apple -c "some command" will have to be change to su - orange.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
doug mielke
Respected Contributor

Re: Change ownership, chmod?

You can also use SAM to universally change ownerships.