Saturday, November 12, 2011

What are the groups I don't belong to?

So you're running your nice linux box, and everything is fine. Everything? No. All of a sudden you really wonder what groups you're in. No problem, just issue
gniourf@somewhere:~$ groups
and you'll be okay. Hey, but wait, in fact that was not exactly your question. In fact, after a deep thought, you realize that your question was the opposite! You were wondering what groups you're not in! If you know a little bit of sed, and if you know how the entries of the /etc/group are formatted, you realize that this one-liner will do the job!
gniourf@somewhere:~$ sed "/\b$USER\b/d;s/:.*//" /etc/group | tr \\n ' '; echo
The piped tr is just here because you don't want to have only one group per line, and the echo to have a new line after all this junk.
You could even add an alias in your .bashrc, or make a function, depending on your needs.

Cheers!

No comments:

Post a Comment