有人请帮我以下代码的输出是什么?
egrep -v '.*:\*|:\!' /etc/shadow |awk -F: '{print $1}'
你为什么不试试呢?
这是一个有密码的用户列表。
其他用户在文件中有一个*
或!
之后。name:
/etc/shadow
打印 /etc/shadow 文件的用户(第一列)
此命令从 /etc/shadow 文件中提取用户名列表。/etc/shadow 文件存储系统上用户的加密密码和一些附加属性。
该命令的第一部分egrep
过滤掉没有设置密码的用户 - 所以这将是用于某些服务的用户帐户。
第二部分awk
打印命令输出的第一列egrep
- 列:
由-F
. 输出的第一列包含用户名。
解释 :
egrep - Search the pattern with using regular expression
-v - Invert of matching pattern that mean matched pattern will not executed
'.*:\*|:\!'- That mean Any character and colon occur then the exact * found not
any charater of star ( For example User only password maintain
other than password field contain * .
awk -F: - Set the delimiter is ":"
'{print $1}' - print the first column .
密码字段包含该行将打印的加密密码,否则 * 出现在不匹配的密码字段中。
这里完全不需要用egrep
,awk
都可以搞定:
awk -F: '$2!~/[*!]/ {print $1}' /etc/shadow
正如其他人指出的那样,这列出了所有不包含*
也不包含!
在第二个字段中的用户。
这将为所有用户提供密码。