Question

Will someone please help me what is the output of the following code?

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

Solution

Why don't you try it?

It's a list of users who do have a password.
The other users have a * or ! after the name: in the /etc/shadow file.

OTHER TIPS

prints the users of /etc/shadow files (first column)

This command extracts a list of usernames from the /etc/shadow file. The /etc/shadow file stores the encrypted passwords of the users on the system and some additional properties.

The first part of the command egrep filters out the users who do not have a password set - so this will be the user accounts used for certain services.

The second part awk prints the first column of output from the egrep command - the columns are separated by a : character as specified by the -F. The first column of output contains the usernames.

Explanation :

    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 .

The password field contain encrypted password that the row will printed else * occur in the password filed that will not match.

There are no need at all to use egrep here, awk can do it all:

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

And as other points out, this list all user that does not contain * nor ! in second field.
This will give all user with password.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top