How to change the primary monitor in Ubuntu or other Linux distributions

Using dual or multiple monitors in Linux is relatively straightforward as most monitors are automatically detected on the major distributions. However, Gnome does not give an option for specifying which monitor is the primary – that is to say the monitor which holds the panels by default and is considered the ‘default’ display. Fortunately, the xrandr utility can easily switch which monitor is the primary. Copy and paste the following script into a text file called monitor-switcher.sh.

#!/bin/bash
# Author: Andrew Martin
# Credit: http://ubuntuforums.org/showthread.php?t=1309247
echo "Enter the primary display from the following:"			# prompt for the display
xrandr --prop | grep "[^dis]connected" | cut --delimiter=" " -f1	# query connected monitors
 
read choice								# read the users's choice of monitor
 
xrandr --output $choice --primary					# set the primary monitor

Once saved, make it executable by typing chmod +x monitor-switcher.sh into the terminal. Then, run it by typing ./monitor-switcher.sh. The script will then display a list of all detected monitors – type in the displayed name of the monitor you wish to make primary and hit enter. The script will then change the primary monitor immediately. Below is a sample run of the script:

$ ./monitor-switcher.sh
Enter the primary display from the following:
VGA1
LVDS1
VGA1

This article has been reposted from here