Section 3.32. Changing Groups: newgrp


[Page 76 (continued)]

3.32. Changing Groups: newgrp

If you're a member of several groups and then you create a file, to what group does the file belong? Well, although you may be a member of several groups, only one of them is your effective group at any given time. When a process creates a file, the group ID of the file is set to the process's effective group ID. This means that when you create a file from the shell, the group ID of the file is set to the effective group ID of your shell. In this example session, I was a member of the "cs" and "music" groups, and my login shell's effective group name was "cs."

The system administrator is the one who chooses which one of your groups is used as your login shell's effective group ID. The only way to permanently alter your login shell's effective group ID is to ask the system administrator to change it. However, you may create a shell with a different effective group ID by using the newgrp utility (Figure 3-44).


[Page 77]

Figure 3-44. Description of the newgrp command.

Utility: newgrp { - | groupname }

The newgrp utility, when invoked with a group name as an argument, creates a new shell with an effective group ID corresponding to the group name. The old shell sleeps until you exit the newly created shell. You must be a member of the group that you specify. If you use a dash (-) instead of a group name as the argument, a shell is created with the same settings as the shell that was created when you logged into the system.


In the following example, I created a file called "test1" from my login shell, which had an effective group of "cs." I then created a temporary shell with an effective group of "music" and then created a file called "test2." I then terminated the shell and went back to the original shell, where I obtained a long listing of both files:

$ date > test1           ...create from a "cs" group shell. $ newgrp music           ...create a "music" group shell. $ date > test2           ...create from a "music" group shell. ^D      ...terminate the new shell. $ ls -l test1 test2      ...look at each file's attributes. -rw-r--r--   1    glass  cs     29 Jan 31 22:57  test1 -rw-r--r--   1    glass  music  29 Jan 31 22:57  test2 $ _ 





Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net