How do I move window buttons from left to right using command line or by editing a specific file?

You can move buttons to the right with:

gsettings set org.gnome.desktop.wm.preferences button-layout ':close,minimize,maximize'

or, maybe better to twitch "close" button with "maximize" button:

gsettings set org.gnome.desktop.wm.preferences button-layout ':maximize,minimize, close'

And move them back to the left with:

gsettings set org.gnome.desktop.wm.preferences button-layout 'close,minimize,maximize:'

To get the current settings, use:

gsettings get org.gnome.desktop.wm.preferences button-layout

See man gsettings for more info, and, as a bonus:

dconf Editor

In this case the changes are made in ~/.config/dconf/user file which is expected to be in the binary dconf (GVDB) database format. Only programs like dconf Editor or gsettings can safely edit this file.

More about:

  • dconf System Administrator Guide
  • Do dconf use EXI binary XML?
  • What is dconf, what is its function, and how do I use it?
  • What are the differences between gconf and dconf?