LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-17-2010, 06:15 AM   #1
gardenair
Member
 
Registered: Oct 2004
Location: LH
Posts: 648

Rep: Reputation: 45
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
 
Old 03-17-2010, 06:18 AM   #2
Sayan Acharjee
Member
 
Registered: Feb 2010
Location: Chennai, India
Distribution: Manjaro
Posts: 624

Rep: Reputation: 64
Try this:
Quote:
#usermod -G Marketing username
 
Old 03-17-2010, 06:21 AM   #3
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 573

Rep: Reputation: 61
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.
 
Old 03-17-2010, 06:34 AM   #4
gardenair
Member
 
Registered: Oct 2004
Location: LH
Posts: 648

Original Poster
Rep: Reputation: 45
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 ?
 
Old 03-17-2010, 06:36 AM   #5
Sayan Acharjee
Member
 
Registered: Feb 2010
Location: Chennai, India
Distribution: Manjaro
Posts: 624

Rep: Reputation: 64
Quote:
Originally Posted by gardenair View Post
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
 
Old 03-17-2010, 06:44 AM   #6
Zuulie
LQ Newbie
 
Registered: Mar 2010
Location: London
Distribution: Ubuntu
Posts: 16

Rep: Reputation: 1
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
 
Old 03-17-2010, 06:47 AM   #7
gardenair
Member
 
Registered: Oct 2004
Location: LH
Posts: 648

Original Poster
Rep: Reputation: 45
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
 
Old 03-17-2010, 06:51 AM   #8
gardenair
Member
 
Registered: Oct 2004
Location: LH
Posts: 648

Original Poster
Rep: Reputation: 45
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.
 
Old 03-17-2010, 06:52 AM   #9
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
Man pages will tell you.
Code:
man grep
man egrep
 
Old 03-17-2010, 06:54 AM   #10
Sayan Acharjee
Member
 
Registered: Feb 2010
Location: Chennai, India
Distribution: Manjaro
Posts: 624

Rep: Reputation: 64
Basically grep and egrep is same command, look into the man page for more information.
#man grep
 
Old 03-17-2010, 06:57 AM   #11
Zuulie
LQ Newbie
 
Registered: Mar 2010
Location: London
Distribution: Ubuntu
Posts: 16

Rep: Reputation: 1
Quote:
Originally Posted by gardenair View Post
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.
 
Old 03-17-2010, 07:04 AM   #12
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
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.)
 
Old 03-17-2010, 07:14 AM   #13
Zuulie
LQ Newbie
 
Registered: Mar 2010
Location: London
Distribution: Ubuntu
Posts: 16

Rep: Reputation: 1
Quote:
Originally Posted by jamescondron View Post
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
 
Old 03-17-2010, 07:17 AM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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
 
Old 03-17-2010, 07:36 AM   #15
jwl17330536
Member
 
Registered: Feb 2010
Location: Raleigh, NC
Posts: 83

Rep: Reputation: 22
Quote:
Originally Posted by Zuulie View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to list user in Linux box, add an user to a group! steady_lfcfan Linux - Newbie 12 01-27-2013 01:14 PM
how to add a user to a new group? emanresu Linux - Newbie 5 11-21-2005 08:18 AM
add user to group brandnewbie Linux - Newbie 3 08-08-2004 04:53 PM
how to add a user to a certain group? feetyouwell Linux - Software 2 01-13-2004 11:56 AM
how can i add a user to a group? doublefailure Linux - General 14 07-10-2002 11:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration