Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-18-2011, 04:49 PM
|
#1
|
LQ Newbie
Registered: Feb 2009
Posts: 6
Rep:
|
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.
|
|
|
01-18-2011, 06:29 PM
|
#2
|
Member
Registered: Oct 2010
Location: Cleveland
Distribution: Slackware, Fedora, RHEL (4,5), LFS 6.7, CentOS
Posts: 258
Rep:
|
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.
|
01-18-2011, 06:45 PM
|
#3
|
LQ Newbie
Registered: Feb 2009
Posts: 6
Original Poster
Rep:
|
Quote:
Originally Posted by zer0signal
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.
|
|
|
01-18-2011, 06:54 PM
|
#4
|
Member
Registered: Oct 2010
Location: Cleveland
Distribution: Slackware, Fedora, RHEL (4,5), LFS 6.7, CentOS
Posts: 258
Rep:
|
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.
|
01-18-2011, 07:46 PM
|
#5
|
Member
Registered: Jan 2008
Distribution: RHEL, CentOS, Ubuntu
Posts: 379
Rep:
|
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.
|
01-18-2011, 07:58 PM
|
#6
|
Member
Registered: Oct 2010
Location: Cleveland
Distribution: Slackware, Fedora, RHEL (4,5), LFS 6.7, CentOS
Posts: 258
Rep:
|
nice! I need to play around with awk and sed more! thx for the info frndrfoe!
|
|
|
01-18-2011, 08:05 PM
|
#7
|
LQ Newbie
Registered: Feb 2009
Posts: 6
Original Poster
Rep:
|
Quote:
Originally Posted by frndrfoe
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.
|
|
|
All times are GMT -5. The time now is 03:22 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|