The chgrp Command

The ls -l command lists the username of the file owner and the group name assigned to the file. In all of the examples shown previously, the user is craig, and the group is users. By default, the file is assigned the owner's primary GID, which is the GID assigned to the user in the /etc/passwd file. This might not be what you want, particularly if access to the files should be limited to a group that logs in to the system to jointly work on the file. Use the chgrp command to change the group of a file:

$ chgrp rnd report.txt $ ls -l report.txt

-rw-r----- 1 craig rnd 16513 May 18 14:22 report.txt

In this example, the group of the report.txt file is changed to rnd. Now, craig has read and write permissions for this file, and anyone in the group rnd has read permission. All other users have no access at all.

Note craig, who is the owner of the file, must be a member of the rnd group to change the file to that group. Unless you're the root user, you cannot change a file to a group of which you're not a member.

This is a good example of how files are shared using the "mainframe model." Anyone in the rnd group can copy the report.txt file to their home directory where they can modify the copy by adding their comments and changes. The person in charge of the report can then look at the comments and changes using a command such as diff, and decide what should be included in the final copy. Only the person in charge of the report can actually write to the master copy.

Sharing files by logging in to the server can work with any client system. It doesn't even require a client computer; a terminal will work just fine. But most users have powerful desktop computers that have the software tools that they like best. A better way to share files lets users work with the files on their desktop systems with the applications they like. Both Unix and Microsoft Windows offer such a service. For Unix systems, Network File System is the most popular service that provides this type of file sharing.

Was this article helpful?

0 0

Post a comment