首页 > 解决方案 > 使用 chage 和 grep 命令使密码过期

问题描述

我的 chage -l $person 命令可以完美地将所有密码信息显示到屏幕上,但我需要使用 grep 和 cut 命令来获取密码到期日期。我不能使用 awk 命令,因为我们还没有在课堂上学习它,所以我坚持使用 cut 和 grep 来获取我需要的行。

Last password change                                    : Feb 19, 2020
Password expires                                        : Jun 18, 2020
Password inactive                                       : Jun 28, 2020
Account expires                                         : never
Minimum number of days between password change          : 0
Maximum number of days between password change          : 120
Number of days of warning before password expires       : 10

我试过了

chage -l "$person" | grep 'Password expires' | cut -d ':' 

这是怎么回事?

标签: linuxgrepcut

解决方案


您缺少告诉它要打印哪一列的-f选项。cut

chage -l "$person" | grep 'Password expires' | cut -d ':' -f 2

推荐阅读