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. |
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... |
Quote:
Do you know if userdel -f xkcd* would work? Where xkcd* is a list of users whose username begins with xkcd. |
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. |
You could build the list from /etc/passwd
Code:
awk -F":" '{ print $1 }' /etc/passwd |grep '^xkcd' >users.txt Code:
getent passwd | awk -F":" '{ print $1 }' | grep '^xkcd' >users.txt |
nice! I need to play around with awk and sed more! thx for the info frndrfoe!
|
Quote:
|
All times are GMT -5. The time now is 09:38 AM. |