This shows you the differences between two versions of the page.
— |
it_tips:shelltricks [2019/02/06 17:52] (current) florido created |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Various useful shell tricks ====== | ||
+ | ===== How do I switch to a different group I belong to? ===== | ||
+ | |||
+ | In unix inspired operating systems one can see whose groups they belong to by using the ''id'' command: | ||
+ | |||
+ | <code:bash> | ||
+ | [pflorido@pptest-iridium ~]$ id | ||
+ | uid=6312(pflorido) gid=34000(clusterusers) groups=34000(clusterusers),6300(hep),6500(npusers),46300(ppguests) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 | ||
+ | [pflorido@pptest-iridium ~]$ touch testgrp | ||
+ | [pflorido@pptest-iridium ~]$ ls -l testgrp | ||
+ | -rw-r-----. 1 pflorido clusterusers 0 6 feb 18.09 testgrp | ||
+ | </code> | ||
+ | |||
+ | The ''gid'' field shows the //primary group//, that is, the first group you belong to and with which one's files will be created. | ||
+ | |||
+ | If one wants to switch to another primary group so that the files are created with a different group name, one can use ''newgrp'': | ||
+ | |||
+ | <code:bash> | ||
+ | [pflorido@pptest-iridium ~]$ newgrp hep | ||
+ | uid=6312(pflorido) gid=6300(hep) groups=6300(hep),6500(npusers),34000(clusterusers),46300(ppguests) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023bash-4.1$ touch testnewgrp | ||
+ | bash-4.1$ ls -l testnewgrp | ||
+ | -rw-r-----. 1 pflorido hep 0 6 feb 18.27 testnewgrp | ||
+ | </code> | ||
+ | |||
+ | Note that group switching starts another login shell, so you can use ''exit'' to go back to your previous group. | ||
+ | |||
+ | <code:bash> | ||
+ | bash-4.1$ exit | ||
+ | exit | ||
+ | [pflorido@pptest-iridium ~]$ id | ||
+ | uid=6312(pflorido) gid=34000(clusterusers) groups=34000(clusterusers),6300(hep),6500(npusers),46300(ppguests) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 | ||
+ | </code> |