1

有人请帮我以下代码的输出是什么?

egrep -v '.*:\*|:\!' /etc/shadow |awk -F: '{print $1}'
4

5 回答 5

2

你为什么不试试呢?

这是一个有密码的用户列表。
其他用户在文件中有一个*!之后。name:/etc/shadow

于 2014-04-21T12:00:24.193 回答
1

打印 /etc/shadow 文件的用户(第一列)

于 2014-04-21T12:02:32.343 回答
1

此命令从 /etc/shadow 文件中提取用户名列表。/etc/shadow 文件存储系统上用户的加密密码和一些附加属性。

该命令的第一部分egrep过滤掉没有设置密码的用户 - 所以这将是用于某些服务的用户帐户。

第二部分awk打印命令输出的第一列egrep- 列:-F. 输出的第一列包含用户名。

于 2014-04-21T12:02:47.297 回答
1

解释 :

    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 .

密码字段包含该行将打印的加密密码,否则 * 出现在不匹配的密码字段中。

于 2014-04-21T12:12:01.447 回答
1

这里完全不需要用egrepawk都可以搞定:

awk -F: '$2!~/[*!]/ {print $1}' /etc/shadow

正如其他人指出的那样,这列出了所有不包含*也不包含!在第二个字段中的用户。
这将为所有用户提供密码。

于 2014-04-21T15:11:21.743 回答