Find the answer to your Linux question:
Results 1 to 9 of 9
I am trying to create a bash script that will automatically find all the files owned by Root user (or any other user) and changed the ownership of these files ...
  1. #1
    Just Joined!
    Join Date
    May 2008
    Posts
    10

    changing all files owned by root and assigned to other user

    I am trying to create a bash script that will automatically find all the files owned by Root user (or any other user) and changed the ownership of these files to an other user.
    Is there is anybody who knows how to do this and can help?

    Thanks,

  2. #2
    oz
    oz is offline
    forum.guy
    Join Date
    May 2004
    Location
    arch linux
    Posts
    18,096
    Welcome to the forums!

    Just curious... what would be the purpose for this script?
    oz

    new members/users: read this first | new member faq
    no private messages requesting computer support - post them on the forums!
    please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.

  3. #3
    Just Joined!
    Join Date
    Aug 2007
    Posts
    28
    you can do this with 'find', you will find with google a lot of help here, the syntax isn't present at the moment, watch -exec... in conjunction with find...

  4. #4
    Just Joined!
    Join Date
    May 2008
    Posts
    10

    just to change an ownership of files automatically

    Quote Originally Posted by ozar View Post
    Welcome to the forums!

    Just curious... what would be the purpose for this script?
    the purpose of this script is just to automate changing the ownership of files by using bash script.
    Do you know how to do it?
    Last edited by adamof99; 10-12-2008 at 02:12 PM. Reason: correction

  5. #5
    Super Moderator MikeTbob's Avatar
    Join Date
    Apr 2006
    Location
    Texas
    Posts
    7,144
    I don't know the answer to your question but I'm with ozar on this one because I think I know where he is going with this. Why would you want to change any file owned by root? Did you know that you can really truly hose your system if you did this? It sounds pretty hardcore to me, even malicious.
    I do not respond to private messages asking for Linux help, Please keep it on the forums only.
    All new users please read this.** Forum FAQS. ** Adopt an unanswered post.

  6. #6
    oz
    oz is offline
    forum.guy
    Join Date
    May 2004
    Location
    arch linux
    Posts
    18,096
    Quote Originally Posted by adamof99 View Post
    the purpose of this script is just to automate changing the ownership of files by using bash script.
    Yeah, that's what you said in your original post. I'm just wondering why a script that can do this would be needed?
    oz

    new members/users: read this first | new member faq
    no private messages requesting computer support - post them on the forums!
    please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.

  7. #7
    Just Joined!
    Join Date
    May 2008
    Posts
    10

    Forget aboub Root

    Quote Originally Posted by MikeTbob View Post
    I don't know the answer to your question but I'm with ozar on this one because I think I know where he is going with this. Why would you want to change any file owned by root? Did you know that you can really truly hose your system if you did this? It sounds pretty hardcore to me, even malicious.
    OK, forget about Root.
    How can you change all files owned by user1 and assigne the ownership to user2?

    I used root just an example, it could be any user

  8. #8
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    (sigh)

    I'm guessing this guy's legit, and he'll soon find a way anyway. So:
    Code:
    find topdirectoryname -user fred -exec chown barney '{}' \;
    Or, if you wish to change also the group name of the file's ownership to match the new user name, find the new user's group name and plug it into this:

    Code:
    find topdirectoryname -user fred -exec chown barney:barneygroup '{}' \;
    And I stress this advice previously given by MikeTbob about doing this for files currently owned by root:
    Did you know that you can really truly hose your system if you did this?
    Another caution: Not only will this change the files under the specified directory, but it will change the directory itself, if the ownership matches.

    Hope this helps. Use this power not for evil, but for good.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  9. #9
    Just Joined!
    Join Date
    May 2008
    Posts
    10

    Thanks

    Quote Originally Posted by wje_lf View Post
    (sigh)

    I'm guessing this guy's legit, and he'll soon find a way anyway. So:
    Code:
    find topdirectoryname -user fred -exec chown barney '{}' \;
    Or, if you wish to change also the group name of the file's ownership to match the new user name, find the new user's group name and plug it into this:

    Code:
    find topdirectoryname -user fred -exec chown barney:barneygroup '{}' \;
    And I stress this advice previously given by MikeTbob about doing this for files currently owned by root:

    Another caution: Not only will this change the files under the specified directory, but it will change the directory itself, if the ownership matches.

    Hope this helps. Use this power not for evil, but for good.
    Thanks wje_lf, Mike and thanks all
    I am using this on my own test system and it's for Good of course

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...