Find the answer to your Linux question:
Results 1 to 3 of 3
Hi everyone, I was looking for some code to check wheter a group exists or not in shell. Without going throug the entire /etc/group file. For users i found this: ...
  1. #1
    Just Joined!
    Join Date
    Dec 2009
    Posts
    2

    Linux Shell Group exists

    Hi everyone,

    I was looking for some code to check wheter a group exists or not in shell.
    Without going throug the entire /etc/group file.

    For users i found this:

    Code:
    if id USERID > /dev/null 2>&1
    then
    echo "User exists"
    else
    echo "User non existant." 
    fi

  2. #2
    Just Joined!
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    9
    Is there an issue with going though the etc/group file? Everything I dug up uses it.

  3. #3
    Just Joined!
    Join Date
    May 2006
    Posts
    4
    Quote Originally Posted by Daniel_B View Post
    Is there an issue with going though the etc/group file? Everything I dug up uses it.
    You are not doing any operation on /etc/group file except searching a strin. So, I don't think so ther will be any issue.
    Use the follwing command to check the existence of group.
    grep -i "^groupname" /etc/group

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...