Linux: How can I display all linux users that have an UID between 300 and 500?

536 Views Asked by At

I want to display all users that its UID between 300 and 500. I tried the grep command but I can't get the result that I need.

I tried this syntax, but it does not work:

cat /etc/passwd | grep *:[300-500]
2

There are 2 best solutions below

6
On BEST ANSWER
egrep 'x:3[0-9][0-9]:|x:4[0-9][0-9]:|x:500:' /etc/passwd

or more eloquent

egrep 'x:[3-4][0-9][0-9]:|x:500:' /etc/passwd
2
On

Using awk, here is your answer:

awk -F: '$3 < 500 && $3 > 300 { print $0 }' /etc/passwd

You can print $1 if you just want the username.