Trying to get a unique list of shells on my system. When I run this command:
cat /etc/passwd | cut -d ':' -f 7 | uniq
I get:
/bin/bash
/bin/sync
/sbin/shutdown
/sbin/halt
/bin/bash
I can't figure out why uniq
isn't doing what I want. What don't I understand?
I tried taking this output, making a copy, replacing one of the /bin/bash
lines with the other in the copy, and then diff
ing the files and I got no output, so I'm guessing not a hidden character?
getent passwd | awk -F: '{s[$7]++}END{for(i in s)print i, s[i]}'
will show the list of shells and how many users are using each. Notice that the user database is NOT always/etc/passwd
, so you better use a nss-aware tool likegetent
. – Jan 28 '21 at 18:51/etc/shells
only lists the shells that a regular user can choose with thechsh
tool. The root can set the shell of a user to any program she likes (withchsh
or other tool). Notice how that list does not include/bin/sync
. – Jan 28 '21 at 18:55