"cut" the user names from /etc/passwd and then running a loop over them. Show Sample Output
This is a standard procedure for me, whenever I set up a new Raspberry Pi system. Because the default user is "pi", I quickly replace it with my own (e.g. "kostis"), but I have to substitute that user to all of pi's groups first, before deleting the default account. xargs helps a lot with that in a single line, while avoiding boring "for" loops. For everything trickier, there's always "parallel" :)
Assuming a convention looking group file, this command will eject oldspiderman from the leagueofsuperfriends group and add newspiderman: oldspiderman:x:551: aquaman:x:552: superman:x:553: newspiderman:x:554: leagueofsuperfriends:x:1000:superman,oldspiderman,superman,aquaman
NSFW - use this on personal laptops where you want your personal user to have all the groups Show Sample Output
an alternative to this one with only 2 processes https://www.commandlinefu.com/commands/view/25844/quickly-add-a-new-user-to-all-groups-the-default-user-is-in
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: