Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I understand what the commands chown and chgrp do however do not understand why you would want to use them apart from assigning ownership to either another user or group? Is this for security purposes or for some other reason?

share|improve this question
    
The chown command can be used to change both user and group ownership, while the chgrp command can only be used to change group ownership dba-oracle.com/linux/chown_chgrp_command_tips.htm –  moomoochoo Aug 16 '13 at 3:09

4 Answers 4

up vote 10 down vote accepted

Linux or other Unix-style-systems are built as a multi user systems.

You have to understand that in this concept not only natural persons count as users, daemons or others programs might run as their own user.

For example: It makes sense to create a dedicated user for the apache service, if you want to run a webserver. In this way apache cannot corrupt files for which it has no permission, mostly due it neither directly owns the files nor is in any group the user is in.

Basically you seperate access to files, by assigning multiple groups to users you can define spefically who and how they can access certain files.

Btw chown :group /path/file does the same thing chgrp does, note the colon in front of the groupname, by using chown user:group /path/file you can do both.

I should add that the file permissions have to be set accordingly. Using chmod you can set the permission flags (read, write, execute) on files for user, group and world.

share|improve this answer
    
Thanks. I wasn't aware that I could execute the command chown as chown :groupname filename. I thought I had to include a username. With the exclusion of the username, I take it as you mentioned, it would have the same result as chgrp groupname. Is that right? –  PeanutsMonkey Mar 27 '12 at 21:27
    
Yes, thats pretty much how I change groups under linux all the time. Thus I have no idea if chown is actually missing functionality that chgrp might have. For me it works :) –  Baarn Mar 27 '12 at 21:34

It's due to one simple thing called the Unix philosophy.

Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.

At least that's what I assume :)

share|improve this answer

If you have a bunch of files saved on a USB flash drive created on one OS and need to use some of those files or all of them on another (Linux) OS, you may need to run a find command and in one instance traverse down a directory tree to chown all of the files and then in another find command follow up with a chgrp command using the -exec feature of the find command in order to use the files (presumably with different user and group ids) so that the files can be used on both different Linux OSes.

share|improve this answer

You have understood exactly: you use chown to change the ownership or group of a file to hand over ownership to someone else. You use chmod to change the permissions associated with one of the owners.

There isn't a deeper need that you have missed, just the general set of shallow needs expressed by those operations. Millions of reasons why some other user should own a file, but none of them deeper than "because we do it that way".

share|improve this answer
    
Try to chown a file to another user if you're not root. –  Daniel Beck Mar 27 '12 at 19:36
    
@DanielBeck - sorry, your point has escaped me here. –  Daniel Pittman Mar 27 '12 at 19:42
    
@Daniel Beck - I know you can't change ownership of a file or directory without being the root user or the person or account that created the file or directory. –  PeanutsMonkey Mar 27 '12 at 23:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.