/etc/passwdからユーザー名とログインシェルを、各行の項目として取り出すコマンドはどれか。
- A column -s : 1,7 /etc/passwd
- B chop -c 1,7 /etc/passwd
- C colrm 1,7 /etc/passwd
- D cut -d: -f1,7 /etc/passwd
正解:D
理由
/etc/passwdはコロン区切りで、ユーザー名は第1、ログインシェルは第7項目である。区切り文字とフィールド番号の指定は次のとおりである。
cut -d: -f1,7
選択肢ごとの説明
- A. column -s : 1,7 /etc/passwd
columnはこの引数で第1・第7フィールドだけを抽出するコマンドではない。
- B. chop -c 1,7 /etc/passwd
この用途の標準コマンド名ではない。
- C. colrm 1,7 /etc/passwd
colrmは列を削除する。
- D. cut -d: -f1,7 /etc/passwd
区切りをコロン、項目を1と7に指定する。