LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-18-2011, 04:49 PM   #1
nycblkboy
LQ Newbie
 
Registered: Feb 2009
Posts: 6

Rep: Reputation: 0
Unhappy Delete users in bulk


Is there a way to remove users in bulk? Maybe by a range of user id numbers.

I help run a school server for our Linux class. I create temp accounts for tests and now I just want to delete them. I really should delete the old users too but the Professer likes to let them have access even after the class.
 
Old 01-18-2011, 06:29 PM   #2
zer0signal
Member
 
Registered: Oct 2010
Location: Cleveland
Distribution: Slackware, Fedora, RHEL (4,5), LFS 6.7, CentOS
Posts: 258

Rep: Reputation: 29
Maybe use some type of script to take input from you about who you want to useradd -m "username" into the system while taking that variable that was used for the input and redirecting it to another file >> users.txt That is to be read later when making a script to remove userdel -f < /location/users.txt

obviously ran as either sudo or root.

the quickest idea I can come up with...

Last edited by zer0signal; 01-18-2011 at 06:30 PM.
 
1 members found this post helpful.
Old 01-18-2011, 06:45 PM   #3
nycblkboy
LQ Newbie
 
Registered: Feb 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by zer0signal View Post
Maybe use some type of script to take input from you about who you want to useradd -m "username" into the system while taking that variable that was used for the input and redirecting it to another file >> users.txt That is to be read later when making a script to remove userdel -f < /location/users.txt

obviously ran as either sudo or root.

the quickest idea I can come up with...
Good idea i'm going to add a few accounts and try it.
Do you know if userdel -f xkcd* would work? Where xkcd* is a list of users whose username begins with xkcd.
 
Old 01-18-2011, 06:54 PM   #4
zer0signal
Member
 
Registered: Oct 2010
Location: Cleveland
Distribution: Slackware, Fedora, RHEL (4,5), LFS 6.7, CentOS
Posts: 258

Rep: Reputation: 29
I don't think you can use the wildcard like that. =(
But I am not a great scripter, where I would look is into into a loop function for userdel, that would just keep that script running till it reached the end of user.txt.

Last edited by zer0signal; 01-18-2011 at 06:55 PM.
 
1 members found this post helpful.
Old 01-18-2011, 07:46 PM   #5
frndrfoe
Member
 
Registered: Jan 2008
Distribution: RHEL, CentOS, Ubuntu
Posts: 379

Rep: Reputation: 38
You could build the list from /etc/passwd
Code:
awk -F":" '{ print $1 }' /etc/passwd |grep '^xkcd' >users.txt
or from a directory service
Code:
getent passwd | awk -F":" '{ print $1 }' | grep '^xkcd' >users.txt
 
2 members found this post helpful.
Old 01-18-2011, 07:58 PM   #6
zer0signal
Member
 
Registered: Oct 2010
Location: Cleveland
Distribution: Slackware, Fedora, RHEL (4,5), LFS 6.7, CentOS
Posts: 258

Rep: Reputation: 29
nice! I need to play around with awk and sed more! thx for the info frndrfoe!
 
Old 01-18-2011, 08:05 PM   #7
nycblkboy
LQ Newbie
 
Registered: Feb 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by frndrfoe View Post
You could build the list from /etc/passwd
Code:
awk -F":" '{ print $1 }' /etc/passwd |grep '^xkcd' >users.txt
or from a directory service
Code:
getent passwd | awk -F":" '{ print $1 }' | grep '^xkcd' >users.txt
Buliding the list not be a problem. I can just take the passwd file import it into excel and erase the info i don't need and save it as text. But thanks I keep forgetting how powerful Unix is.
 
  


Reply

Tags
fedora, server



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 add bulk of users in fedora 10 asifbasha Linux - Software 3 08-18-2009 08:09 PM
Setting Disk Quota for Bulk Users haariseshu Linux - Server 3 06-10-2009 08:51 AM
Add bulk users at a same time mudasar Linux - Networking 1 11-20-2005 01:56 PM
Mail Setup for Bulk Users thadco Linux - Newbie 1 06-25-2005 01:24 PM
how do i delete users? ShawnD Linux - General 9 07-22-2002 10:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:02 PM.

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