Results 1 to 10 of 10
|
|
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
-
08-18-2005 #1Linux Newbie
- Join Date
- Jul 2004
- Location
- Calcutta, India
- Posts
- 220
command to view list of ALL users and groups
Can nebody tell me a command ( or combo of cmds, so that I can put it in a shell script ) to view list of ALL users ( may or may NOT be logged in, preferably non-system users only ) ??
and something similar for a list of ALL groups ??
I need it badly but cant really figure it out ...
-
08-18-2005 #2Linux Engineer
- Join Date
- Apr 2005
- Location
- Buenos Aires, Argentina
- Posts
- 908
cat /etc/passwd | cut -d: -f1
cat /etc/group |cut -d: -f1serzsite.com.ar
"All the drugs in this world won\'t save you from yourself"
-
08-18-2005 #3Linux Newbie
- Join Date
- Jul 2004
- Location
- Calcutta, India
- Posts
- 220
ok .. that is fine ...
now a little bit more .. the output of cat /etc/passwd | cut -d: -f1
shows system users as well .. I want to show only the non-system users,
like my own user account, but NOT root, etc.
ie., on my system, general users have UIDs starting frm 500, so I just wanna check the 3rd field of each line in the passwd file and accordingly print them.
Please help someone, I know this can be done (probably using awk or sed), bcos I had seen similar things before, though I dont remember now.
Thanks for everything so far..
-
08-18-2005 #4Heh, I tried writing it in Bash first (and it almost worked!), but here it is in Perl, which I actually knowCode:
#!/usr/bin/perl -w open PASSWD, "/etc/passwd" or die "$0: Cannot Open File /etc/passwd For Input!!\n"; while(<PASSWD>) { /^(\w+):x:(\d+)/; if($2 > 500) { print "$1\n"; } }
.
-
08-18-2005 #5Linux Newbie
- Join Date
- Jul 2004
- Location
- Calcutta, India
- Posts
- 220
Just figured out another one ...
The $3<=1000 is for the nfsnobody user a/c which has an UID of 65534.Code:#!/bin/sh awk -F: '{if ($3>=500 && $3<=1000) print}' /etc/passwd | cut -d: -f1
Thanks anyway Cabhan, I have already copied your perl soln and added to my archives.
-
08-18-2005 #6
I think that just everyone hates me
.
Hehe, everytime I write some sort of script, someone replies with like a two-line Bash command. Damn you all.
-
08-18-2005 #7Linux Newbie
- Join Date
- Jul 2004
- Location
- Calcutta, India
- Posts
- 220
hmmm .. well actually its NOT that I do not like perl. I simply have never really had the enthusiasm and time to learn it well, as of now. however, I do know about the various capabilities of perl and unless I would have got that soln before checking your reply, I would have stuck to your version only.
But then, as I have said already, I do collect scripts which look interesting to me, and yours is definitely one of them.
-
08-18-2005 #8
Man I am really gonna have to get familiar with gawk. Every time I thinkg I get an idea someone else shows me it at work and I go 'cool'. Cheers for that code, will be used! Although a lot of my new users have much higher UIDs so I've modified it a bit.
-
08-19-2005 #9Linux Newbie
- Join Date
- Jul 2004
- Location
- Calcutta, India
- Posts
- 220
an even shorter one, dunno y it did not come to my mind earlier :
Code:#!/bin/sh awk -F: '{if ($3>=500 && $3<=1000) print $1}' /etc/passwd
-
05-02-2006 #10You are letting your imagination run wild...
Originally Posted by Cabhan

How about this:
Originally Posted by Cabhan
(It doesn't make yours less valid.)Code:#!/usr/bin/perl -w open PASSWD, "/etc/passwd" or die "$0: Cannot Open File /etc/passwd For Input!!\n"; while(<PASSWD>) { /^(\w+):x:(\d+)/; if($2 > 500) { print "$1\n"; } }
"Now, that's not nice..."
Originally Posted by Cabhan


Reply With Quote