I am the lucky owner of a pivot monitor, which screen can be rotated (physically). What is the easiest way to make my display turn when I turn my monitor?

For the moment I first launch the 'Displays' app, and then change the settings and confirm. But this is in fact quite a laboured procedure, since I want to switch my orientation up to a few times per minute.

So is there an indicator for this, or equivalent? Can I set a keyboard shortcut that would launch a dedicated command? In fact I am thinking of something similar to the Windows program iRotate.


Go into Keyboard -> Shortcuts, select "Custom Shortcuts", and press "+" to add a new shortcut.

"Name" is a descriptive name for the action (i.e. "Rotate monitor"). In "Command" type the custom command to run when the shortcut is activated.

Once the shortcut is in the list, select its row, press ENTER, then the key combination you want to activate the shortcut. If there's a conflict, the shortcut manager will tell you so, and you can choose a different combination.

You can have shortcut to enable rotated display and another to bring it back to an upright position. You can even, if you're knowledgeable enough, write a command that maintains state and just toggles between upright/rotated.

Now, as for the command you need to use, it's probably xrandr:

xrandr --output HDMI1 --rotate left

xrandr --output HDMI1 --rotate normal

The output parameter depends on which port your monitor is plugged into. To see what you currently have, type:

xrandr -q

Mine says:

Screen 0: minimum 320 x 200, current 1366 x 768, maximum 8192 x 8192
LVDS1 connected 1366x768+0+0 (normal left inverted right x axis y axis) 309mm x 174mm
   1366x768       60.0*+
   1360x768       59.8     60.0  
   1024x768       60.0  
   800x600        60.3     56.2  
   640x480        59.9  
VGA2 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
DP1 disconnected (normal left inverted right x axis y axis)

In this case my --output would be LVDS1, as all the others are disconnected.

  • 2
    This is excellent. – Agmenor Jan 16 '12 at 6:00
  • I am new to linux and I tried to set this up, but when I use the command nothing happens. Is there something else I have to configure to ensure my custom keyboard shortcuts work? The built in commands work, just not the custom ones I created. I am using Ubuntu 14.04. I followed the directions and wrote the following in the command line. xrandr --output HDMI1 --rotate left I used ctrl+left as the shortcut. When I use that command in the terminal, everything works great. Just not with the keyboard shortcut. – nelsond Dec 25 '14 at 21:58
  • @nelsond did you verify that you are using HDMI1 with xrandr -q? – Elder Geek Jan 25 '15 at 14:16
  • 11
    Hey, doing xrandr -o right also works and doesn't need to specify the current target – whitenoisedb Aug 23 '15 at 14:54
  • 1
    I got output LVDS1 not found; and output HTMI1 not found; thanks to @whitenoisedb's comment I simply used xrandr -o normal, without specifying the --output argument to put the screen back in the normal direction. – Paul Rougieux Sep 14 '17 at 7:58

Works great with

xrandr --output LVDS1 --rotate left
xrandr --output LVDS1 --rotate right
xrandr --output LVDS1 --rotate inverted
xrandr --output LVDS1 --rotate normal
  • 1
    Is there an alternative which doesn't turn my screen on and off (I am using fglrx) – Suici Doga Jun 5 '16 at 14:40
  • perfect solution – Waseem Mar 31 '17 at 5:20

Here is a nice example on how to do it based on sensor input: https://linuxappfinder.com/blog/auto_screen_rotation_in_ubuntu

So basically try the above to identify the screen you want to see rotated. Depending on the model monitor there may be a sensor that sends a signal?

This works nicely for my Lenovo Yoga 2 11 with builtin rotation sensor and it moves the unity dock too.

The script:

# Auto rotate screen based on device orientation

# Receives input from monitor-sensor (part of iio-sensor-proxy package)
# Screen orientation and launcher location is set based upon accelerometer position
# Launcher will be on the left in a landscape orientation and on the bottom in a portrait orientation
# This script should be added to startup applications for the user

# Clear sensor.log so it doesn't get too long over time
> sensor.log

# Launch monitor-sensor and store the output in a variable that can be parsed by the rest of the script
monitor-sensor >> sensor.log 2>&1 &

# Parse output or monitor sensor to get the new orientation whenever the log file is updated
# Possibles are: normal, bottom-up, right-up, left-up
# Light data will be ignored
while inotifywait -e modify sensor.log; do
# Read the last line that was added to the file and get the orientation
ORIENTATION=$(tail -n 1 sensor.log | grep 'orientation' | grep -oE '[^ ]+$')

# Set the actions to be taken for each possible orientation
case "$ORIENTATION" in
xrandr --output eDP1 --rotate normal && gsettings set com.canonical.Unity.Launcher launcher-position Left ;;
xrandr --output eDP1 --rotate inverted && gsettings set com.canonical.Unity.Launcher launcher-position Left ;;
xrandr --output eDP1 --rotate right && gsettings set com.canonical.Unity.Launcher launcher-position Bottom ;;
xrandr --output eDP1 --rotate left && gsettings set com.canonical.Unity.Launcher launcher-position Bottom ;;

and prerequisite for the sensors:

sudo apt install iio-sensor-proxy inotify-tools
  • monitor-sensor doesn't make any outputs. Do you know if I can configure it? I have an hp and lsmod | grep acc shows hp_accel 28672 0 lis3lv02d 20480 1 hp_accel – Mina Michael Mar 5 '17 at 16:34
  • @MinaMichael you might be experiencing a kernel bug. Look here – JrBenito Apr 13 '17 at 17:26
  • It works on kernel 4.8, it can be a bug in later versions indeed, since the script I use stopped working on never versions. Please contribute to the bug report if you can or file a new bug if applicable. – Vincent Gerris Sep 11 '17 at 11:50

I wrote a shell script to do this. (Requires xrandr grep awk)

# invert_screen copyright 20170516 alexx MIT Licence ver 1.0
orientation=$(xrandr -q|grep -v dis|grep connected|awk '{print $4}')
display=$(xrandr -q|grep -v dis|grep connected|awk '{print $1}')
if [ "$orientation" == "inverted" ]; then
   xrandr --output $display --rotate normal
   xrandr --output $display --rotate inverted

If you like one-liners:

[ "$(xrandr -q|grep -v dis|grep con|awk '{print $4}')" == 'inverted' ] && xrandr -o normal || xrandr -o inverted
  • 1
    For me it's $5 instead of $4. – Nicolai Dec 15 '18 at 21:19
  • 1
    With xrandr --version 1.5.0 $5 is working for me (the danger of using text output) [ "$(xrandr -q|grep -v dis|grep con|awk '{print $5}')" != 'inverted' ] && xrandr -o inverted || xrandr -o normal is safer as it defaults to "normal" – Alexx Roche Dec 18 '18 at 17:32

In addition to the script posted in derHugo's answer, On Kubuntu 20.10, I had to change it to {print $5} as well as using bash instead of plain sh. With those minor modifications, my script reads:

# invert_screen copyright 20170516 alexx MIT Licence ver 1.0
orientation=$(xrandr -q|grep -v dis|grep connected|awk '{print $5}')
display=$(xrandr -q|grep -v dis|grep connected|awk '{print $1}')
if [ "$orientation" == "inverted" ]; then
   xrandr --output $display --rotate normal
   xrandr --output $display --rotate inverted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.