{"id":6038,"date":"2016-07-14T11:43:33","date_gmt":"2016-07-14T03:43:33","guid":{"rendered":"http:\/\/rmohan.com\/?p=6038"},"modified":"2016-07-14T11:43:33","modified_gmt":"2016-07-14T03:43:33","slug":"counting-number-of-users-in-a-group-linux","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6038","title":{"rendered":"Counting number of users in a group &#8211; Linux"},"content":{"rendered":"<p><strong>Counting number of users in a group &#8211; Linux<\/strong><\/p>\n<p>Here is a small command to find number of users in particular group on a *nix system. An example for wheel group:<\/p>\n<p>grep wheel \/etc\/group | fgrep -o , | wc -m<\/p>\n<p>Now here&#8217;s a catch, this command actually counts the commas in the line from the group file. So if there are 5 users in the group, the output will be 4. You will have to add a 1 to the output.<\/p>\n<p>So when using it in scripts, one can use it like this:<\/p>\n<p>VAR1=$(($(grep wheel \/etc\/group | fgrep -o , | wc -m) + 1))<br \/>\necho $VAR1<br \/>\n5<\/p>\n<p>Explanation:<\/p>\n<p>First grep will print only the group and its members. The members are seperated by a comma. Next we print the commas using -o option and later count them using wc command. The second example will just add a 1 to it.<\/p>\n<p>Read more at http:\/\/kaustubhghanekar.blogspot.com\/2015\/12\/counting-number-of-users-in-group-linux.html#IXfIGy3o5PEqmMlL.99<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Counting number of users in a group &#8211; Linux<\/p>\n<p>Here is a small command to find number of users in particular group on a *nix system. An example for wheel group:<\/p>\n<p>grep wheel \/etc\/group | fgrep -o , | wc -m<\/p>\n<p>Now here&#8217;s a catch, this command actually counts the commas in the line from [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6038"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6038"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6038\/revisions"}],"predecessor-version":[{"id":6039,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6038\/revisions\/6039"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6038"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6038"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6038"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}