Chown Command



atanere

Well-Known Member
Credits
18
Hi all, can you tell me what the chown command is to set all files to read & write?

Thanks in advance
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).
 

JasKinasis

Well-Known Member
Credits
7,670
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.
 

VP9KS

Well-Known Member
Credits
921
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.
Nice explanation!:)
 

MikeyD

New Member
Credits
0
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
 

wizardfromoz

Administrator
Staff member
Gold Supporter
Credits
18,283
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
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Members online


Top