全力で怠けたい

怠けるために全力を尽くしたいブログ。

ユーザーが所属するグループを表示する groups コマンドのメモ。

ユーザーが所属するグループを表示する groups コマンドの使い方のメモ。

このメモは ubuntu 20.10 の Docker コンテナ上の groups コマンドを使っている。

$ docker container run --rm -it ubuntu:20.10 /bin/bash

groups コマンドのバージョン。

# groups --version
groups (GNU coreutils) 8.32
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David MacKenzie and James Youngman.

groups コマンドの使い方

groups コマンドはユーザーが所属するグループを表示するコマンド。

groups コマンドは使い方に関しては特に書くことがないくらいシンプルなコマンドだけど自分はたまに「あれ、どうやって使うんだっけ」みたいになるので使い方をメモしておく。

基本的な使い方

groups コマンドは groups <ユーザー> みたいにユーザーを指定して実行すると指定したユーザーが所属するすべてのグループの名前を表示する。

# whoami
root

# groupadd employees
# useradd alice --create-home --groups employees

# groups alice
alice : alice employees

groups コマンドは groups みたいにユーザーを指定しないで実行すると groups コマンドを実行したユーザーが所属するすべてのグループの名前を表示する。

# su - alice
$ whoami
alice
$ groups
alice employees

--help オプション: ヘルプ

--help オプションを指定すると groups コマンドの使い方を表示する……んだけど man groups が使えないときにしか使わない。

# groups --help
Usage: groups [OPTION]... [USERNAME]...
Print group memberships for each USERNAME or, if no USERNAME is specified, for
the current process (which may differ if the groups database has changed).
      --help     display this help and exit
      --version  output version information and exit

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report any translation bugs to <https://translationproject.org/team/>
Full documentation <https://www.gnu.org/software/coreutils/groups>
or available locally via: info '(coreutils) groups invocation'