-   Linux - Newbie (
-   -   how to list all locked account in linux? (

robbiezr 04-13-2009 04:28 AM

how to list all locked account in linux?
how to list locked account in linux(redhat)?
I can use the command "passwd -S -username" to list a account who were locked .
who knows how to list all locked accounts with one command.

colucix 04-13-2009 06:51 AM


passwd -S -a | grep LK | cut -d " " -f1

ghostdog74 04-13-2009 07:01 AM


passwd -S -a |awk '/LK/{print $1}'

sundialsvcs 04-13-2009 07:46 AM


Both of these illustrations demonstrate a very common technique that is used throughout Unix/Linux: what I'll call command piping.

In these examples, the output of one command (such as ls is "piped to" another command, which effectively filters its input and sends it down the line.

As the Perl folks like to say, "there's more than one way to do it." Both of these techniques work equally well.

robbiezr 04-13-2009 09:00 PM

Thanks for replying.
I tried the command below :


passwd -S -a | grep LK | cut -d " " -f1

passwd -S -a |awk '/LK/{print $1}'
but the system warns that "passwd: bad argument -a: unknown option".
I think there is no argument -a in this linux version.

I found that if a user is locked .there is a !! symbol in the row in the file /etc/shadow.



brycen 10-05-2009 12:34 PM

Under Debian at least the relevant string is "L" not "LK". So:


passwd -S -a | grep " L " | cut -d " " -f1


passwd -S -a | cut -d " " -f1-2 | grep "L$"

ccrmsc 09-19-2012 12:26 PM

I know this is an old thread but I came up with this solution for RHEL6.

cat /etc/passwd | cut -d : -f 1 | awk '{ system("passwd -S " $0) }'

All times are GMT -5. The time now is 03:00 PM.