Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd please sign up again. Thanks!

Chown Command

Discussion in 'Command Line' started by Jack Makinson, Apr 29, 2017.

  1. Jack Makinson

    Jack Makinson New Member

    Joined:
    Apr 26, 2017
    Messages:
    5
    Likes Received:
    1
    Hi all, can you tell me what the chown command is to set all files to read & write?



    Thanks in advance
     
  2. atanere

    atanere Moderator
    Gold Supporter

    Joined:
    Apr 6, 2017
    Messages:
    335
    Likes Received:
    300
    Hi Jack!

    @Rob just put a bunch of great tutorials on the site here, including this one that exactly covers your question. Please check these out when you get a chance... for Beginners, Intermediate, and Advanced.

    But I'll also clue you in: its chmod that you want, not chown.

    Code:
    chmod 666 your-file.txt
    This will give read and write permissions to everyone for that single file. You can use *.* wildcards to change all files in a directory (but you should carefully consider that before you do).
     
  3. JasKinasis

    JasKinasis Active Member

    Joined:
    Apr 25, 2017
    Messages:
    86
    Likes Received:
    114
    Jack, atanere is 100% correct. You should be using the chmod command NOT chown.
    But atanere failed to explain what chown is and what it does.

    So here goes:
    The chown command is used to change ownership of files and/or directories. (Whereas chmod is used to modifiy the access permissions for owner, group and other users.)

    As atanere has explained, when you want to change the access permissions, you must use chmod.

    You would only use chown when you want to transfer the ownership or the group ownership of files/directories to a different user/group.
    The syntax for the chown command is:
    Code:
    chown {options} {new owner}:{new group} {list of directories and/or files...}
    e.g.
    Code:
    chown dave:users someTextFile
    Would make dave the owner of someTextFile and the group would be users - so anybody in the users group would have group access to the file - their level of access would be dependent on the file permissions that are currently set. Again, if you need to change the permissions for owner, group or other users you would use chmod.

    To change only the owner using chown:
    Code:
    chown {options} {new owner} {list of directories and files...}
    e.g.
    Code:
    chown -R dave ./someFolder
    Would make dave the owner of someFolder. Because we used the -R option, it will recursively apply the ownership to all files/sub-directories in ./someFolder.

    To change only the group ownership:
    Code:
    chown {options} :{new group} {list of directories and files...}
    Or you could use chgrp:
    Code:
    chgrp {options} {new group} {list of directories and files...}
    To summarise:
    When you want to change the permissions for files/directories - use chmod.
    When you want to change ownership of files/directories - use chown, or chgrp.
     
  4. VP9KS

    VP9KS Active Member

    Joined:
    Apr 29, 2017
    Messages:
    157
    Likes Received:
    94
    Nice explanation!:)
     
  5. MikeyD

    MikeyD New Member

    Joined:
    May 5, 2017
    Messages:
    9
    Likes Received:
    10
    Good overview @JasKinasis .

    As with a lot of Linux commands, once you expand the commands their meaning is a lot more clear (and helps me at least remember what they do)

    chown - change owner

    chmod - change mode (I also think of this as modify since you are modifying permissions)

    chgrp - change group

    chroot - change root directory
     
    NagaPradeep, VP9KS and wizardfromoz like this.
  6. wizardfromoz

    wizardfromoz Well-Known Member

    Joined:
    Apr 30, 2017
    Messages:
    233
    Likes Received:
    262
    Not wishing to go off-topic, nor to confuse the OP, but the door has been opened a little with reference to chmod.

    The most common use I make of chmod is with the +x option, with writing simple bash scripts. This changes the script file to an executable file.

    Perhaps Rob might consider incorporating that into his Tutorial?

    Cheers all &

    Avagudweegend

    Wizard
     
    MikeyD likes this.

Share This Page