Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-13-2009, 05:28 AM   #1
LQ Newbie
Registered: Apr 2009
Posts: 2

Rep: Reputation: 0
Smile 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.
Old 04-13-2009, 07:51 AM   #2
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
passwd -S -a | grep LK | cut -d " " -f1
Old 04-13-2009, 08:01 AM   #3
Senior Member
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 243Reputation: 243Reputation: 243
passwd -S -a |awk '/LK/{print $1}'
Old 04-13-2009, 08:46 AM   #4
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,984

Rep: Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444Reputation: 1444

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.
Old 04-13-2009, 10:00 PM   #5
LQ Newbie
Registered: Apr 2009
Posts: 2

Original Poster
Rep: Reputation: 0
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.

Old 10-05-2009, 01:34 PM   #6
LQ Newbie
Registered: Sep 2004
Posts: 7

Rep: Reputation: 0

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$"
Old 09-19-2012, 01:26 PM   #7
LQ Newbie
Registered: Sep 2012
Location: San Jose, CA
Distribution: Centos / Linux RHEL6
Posts: 4

Rep: Reputation: 0
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) }'


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference betwwen : Locked User Account & Disabled User Accounts in Linux ? avklinux Linux - Security 1 02-04-2009 03:30 PM
print user list, showing a locked user account?? royal024 Linux - Newbie 4 10-18-2008 11:57 AM
viewing a locked account tataiermail Linux - General 5 07-11-2007 04:21 AM
How to get a list of users with their password status (expired, account locked...)? ricky_ds Linux - General 6 02-28-2005 10:53 AM
locked pop3-account jonas_the_joker Linux - General 1 10-17-2003 08:08 AM

All times are GMT -5. The time now is 08:00 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration