I want to list the username, id and group on /etc/passwd using the following format: username uid gid
I have used the following:
cut -d: -f1,3,4 /etc/passwd
But it returns username:uid:gid
. How can I format the command to remove the :
or list without it, like this:
root 0 0
daemon 1 1
bin 2 2
...
/etc/passwd
(or/etc/group
) directly. Usegetent passwd
(orgetent group
) instead. /etc/passwd is only one of many possible sources of data for user account info. ditto for /etc/group. See the man pages fornss
,getent
, andnsswitch.conf
. e.g. using @phuclv's awk example:getent passwd | awk -F: '{print $1, $3, $4}'
getent
instead of a comment. That way people can upvote it, and it can potentially be selected as the correct answer to achieve what the OP wants.getent
instead of reading /etc/passwd directly.