Last active
August 13, 2018 20:31
-
-
Save zlatko-minev/5e5f154a60f6cc624a9accc62075dec0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# If the top line line doesn't work, change to #!/bin/bash | |
# Name: list_users.sh | |
# Purpose: List all normal user and system groups in the system. | |
# Tested on RHEL / Debian Linux / BusyBox / GNU/Linux / Mac OS X Sierra Darwin | |
# Author: Zlatko Minev, based on Vivek Gite, under GPL v2.0+ | |
# Original link: https://www.cyberciti.biz/faq/linux-list-users-command/ | |
# See also: http://tuxthink.blogspot.com/2012/03/look-into-etcpasswdetcshadow-and.html | |
# ----------------------------------------------------------------------------------- | |
clear | |
#source ./colors.sh | |
Bold='\033[1m' # Bold | |
BRed='\033[1;31m' # Bold Red | |
ResetTxt='\033[0m' # Text Reset | |
Bar='---------------------------------' | |
_g="/etc/group" | |
#echo "Content of $_g:" | cat - $_g # https://superuser.com/questions/1285136/cat-command-and-echo # echo " " | |
printf "%s${Bold}[ System User Groups ]${ResetTxt}%s\\n" ${Bar} ${Bar} # https://github.com/koalaman/shellcheck/wiki/SC2059 | |
printf "${BRed}%-5s %-15s %-15s %-8s${ResetTxt}\\n" "GID" "Group Name" "Users in Group" "Group Pswd" | |
awk -F':' '{ printf "%-5s %-15s %-15s %-8s\n", $3, $1, $4, $2 }' "$_g" | |
printf '%s%s%s\n\n' "${Bar}" '------------------------' "${Bar}" | |
_p="/etc/passwd" | |
#echo "Content of $_g:" | cat - $_p # echo " " | |
printf "%s${Bold}[ System User Accounts ]${ResetTxt}%s\\n" ${Bar} ${Bar} | |
printf "${BRed}%-5s %-5s %-10s %-16s %-15s %-25s %-10s${ResetTxt}\\n" "GID" "UID" "User Name" "User Info" "User shell" "User Directory" "Has pswd" | |
awk -F':' '{ printf "%-5s %-5s %-10s %-16s %-15s %-25s %-10s\n", $4, $3, $1, $5, $7, $6, $2 }' "$_p" | |
printf '%s%s%s\n\n\n' "${Bar}" '------------------------' "${Bar}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pretty print Linux user groups, users, and key properties ala *nix.