• We had to restore from a backup today after a failed software update. Backup was from 0000 EDT and restored it at 0800 EDT so we lost about 8hrs. Today is 07/20/2024. More info here.

Chown Command

Jack Makinson

New Member
Joined
Apr 26, 2017
Messages
13
Reaction score
3
Credits
68
Hi all, can you tell me what the chown command is to set all files to read & write?

Thanks in advance
 


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).
 
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.
 
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!:)
 
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
 
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
 

Members online


Top