LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to add user in a group? (http://www.linuxquestions.org/questions/linux-newbie-8/how-to-add-user-in-a-group-795996/)

gardenair 03-17-2010 07:15 AM

How to add user in a group?
 
Hi,
I have four users in my red hat linux 9. I want that all these four users should add in a group i.e "Marketing".please guide me that using terminal which command may i write so that the users should added in the group.

Note:- I does't want to use GUI interface to do it.

thanks in advance,
garden

Sayan Acharjee 03-17-2010 07:18 AM

Try this:
Quote:

#usermod -G Marketing username

blacky_5251 03-17-2010 07:21 AM

Code:

for user in john bill mary jane
do
  usermod -G marketing $user
done

Substitute john bill mary and jane for your real user names.

gardenair 03-17-2010 07:34 AM

thanks for the prompt reply. Well the command works fine. Now a question rises that how can I see all four users in "Marketing " Group. Is there anyway command to check it ?

Sayan Acharjee 03-17-2010 07:36 AM

Quote:

Originally Posted by gardenair (Post 3901646)
thanks for the prompt reply. Well the command works fine. Now a question rises that how can I see all four users in "Marketing " Group. Is there anyway command to check it ?

Use this command:
Quote:

#cat /etc/group| grep Martketing

Zuulie 03-17-2010 07:44 AM

You may want to use
Code:

egrep '^Marketing:' /etc/group
to make sure you only get exact matches of "Marketing", especially if you want to use it in a script.

-- Dan

gardenair 03-17-2010 07:47 AM

thanks a lot all of you for guiding me. Well about users and groups in linux and the files related to it, kindly refer me any site in which I may study it in more detail.

Again thanks
garden

gardenair 03-17-2010 07:51 AM

well the command

#cat /etc/group| grep Martketing

and

egrep '^Marketing:' /etc/group

provide same output.So what is the difference in both these and in which situation I may use egrep or cat command.

Iam sure there should be a minor difference.

jamescondron 03-17-2010 07:52 AM

Man pages will tell you.
Code:

man grep
man egrep


Sayan Acharjee 03-17-2010 07:54 AM

Basically grep and egrep is same command, look into the man page for more information.
#man grep

Zuulie 03-17-2010 07:57 AM

Quote:

Originally Posted by gardenair (Post 3901676)
well the command

#cat /etc/group| grep Martketing

and

egrep '^Marketing:' /etc/group

provide same output.So what is the difference in both these and in which situation I may use egrep or cat command.

Iam sure there should be a minor difference.

The significance isn't the type of grep used; it's the usage of regexp that is more explicit.

Your example would match more than "Marketing" (e.g. "Marketing2"), that could cause problems when used in scripts.

jamescondron 03-17-2010 08:04 AM

Nothing like allowing the OP to answer his/her own question, eh? Your answer isn't quite right either.

from the man page:
Quote:

In addition, three variant programs egrep, fgrep and rgrep are available. egrep is the same as grep -E. fgrep is the same as
grep -F. rgrep is the same as grep -r. Direct invocation as either egrep or fgrep is deprecated, but is provided to allow
historical applications that rely on them to run unmodified.

<snip>

Matcher Selection
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see below). (-E is specified by POSIX.)

Zuulie 03-17-2010 08:14 AM

Quote:

Originally Posted by jamescondron (Post 3901694)
Nothing like allowing the OP to answer his/her own question, eh? Your answer isn't quite right either.

from the man page:

LOL. I forgot how these discussions can take off. Quite refreshing.

Yes, you're right. Let's get it entirely right:
Code:

/bin/grep '^Marketing:' /usr/group

chrism01 03-17-2010 08:17 AM

If you're really using red hat linux 9 (codename Shrike) http://en.wikipedia.org/wiki/Red_Hat_Linux, it hasn't been updated, inc security in years. Do yourself (& us ) a favour an get something current eg http://en.wikipedia.org/wiki/CentOS

jwl17330536 03-17-2010 08:36 AM

Quote:

Originally Posted by Zuulie (Post 3901662)
You may want to use
Code:

egrep '^Marketing:' /etc/group
to make sure you only get exact matches of "Marketing", especially if you want to use it in a script.

-- Dan

I'm sure if he were writing a script he wouldn't be asking for help on adding users to a explicit group... My mind tells me he would know that (or google) already.


All times are GMT -5. The time now is 10:06 PM.