Booker

Friday, March 11, 2016

GNU/Linux Groups reloading without reboot/logout

  • Too lazy to reboot.
  • Having too much running important things.
  • Must do it now !

No more reboot !

 the newgrp command is used to start a new session having the group or all new group reread from the groups configuration.

What it does, it starts a new bash session and newly invoked commands use the new groups.

How to do it ?


In your favourite DE press ALT + F2, then type:
bash -c 'newgrp <<< dolphin' (or use nautilus, rox, etc)

Explanation

  • bash will open a new shell session and invoke a command
  • newgrp will reload that session
  • and STDIN redirection will inject commands e.g dolphin into the new session

 Caveats

  • We cannot create new directories/files
  • Renaming files raises error, the renamed file visually looks changed, but refreshing the directory will revert the name.
  • Creating new file does the same thing.
  • Creating new directory does the same thing.

What's possible

Only edit existing files - Useful for Sublime and such to quickly edit something.

For using an IDE

  1. it's useful that we first chown the directory to our username
  2. create the project with the IDE
  3. play around, until everything is written
  4. chown back to the intended group
  5. run the ide either with:
    bash -c 'newgrp <<< ~/.local/bin/idea-IU/bin/idea.sh'
  6. alternatively run it in dolphin's terminal, but that's silly

Troubleshoot and tricks

If you need to pass arguments to the command:
bash -c 'newgrp <<< "dolphin ~/bin"'
Notice the double quotes surround the command,  well, without them nothing will happen :D.

Alternative

sg couchbase -c dolphin
much like the newgrp command, however sg accepts a command

Caveats

you must know the group, alas only one group.
Which means this command sucks!