How to use the command xrandr (with examples)

How to use the command xrandr (with examples)

xrandr is a command-line utility in Linux used to set the size, orientation, and reflection of outputs for a screen. It is commonly used to manage displays in a multi-monitor setup. This article provides examples of different use cases of the xrandr command.

Use case 1: Display the current state of the system

Code:

xrandr --query

Motivation: Displaying the current state of the system is helpful to understand the current screen configuration, including connected outputs, supported resolutions, and refresh rates.

Explanation: The --query option provides information about the connected screens, their resolutions, and available refresh rates. It gives a comprehensive overview of the system’s display capabilities.

Example Output:

Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384
DP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 510mm x 287mm
   1920x1080     60.00*+  50.00    59.94  
   1680x1050     59.88  
   1600x900      60.00  
   ...
HDMI1 disconnected (normal left inverted right x axis y axis)
HDMI2 connected 1920x1080+1920+0 (normal left inverted right x axis y axis) 477mm x 268mm
   1920x1080     60.00*   50.00    59.94  
   1680x1050     59.88  
   1600x900      60.00  
   ...

Use case 2: Disable disconnected outputs and enable connected ones with default settings

Code:

xrandr --auto

Motivation: When a new display is connected to the system, it is often required to enable the display and set it up with default settings. This command automatically detects connected displays and configures them accordingly.

Explanation: The --auto option automatically enables connected outputs and sets them to their default settings, such as resolution and orientation. It disables disconnected outputs to optimize the screen configuration.

Example Output:

Screen 0: minimum 320 x 200, current 3840 x 1080, maximum 16384 x 16384
DP1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 510mm x 287mm
   1920x1080     60.00*+  50.00    59.94  
   1680x1050     59.88  
   1600x900      60.00  
   ...
HDMI2 connected 1920x1080+1920+0 (normal left inverted right x axis y axis) 477mm x 268mm
   1920x1080     60.00*   50.00    59.94  
   1680x1050     59.88  
   1600x900      60.00  
   ...

Use case 3: Change the resolution and update frequency of DisplayPort 1 to 1920x1080, 60Hz

Code:

xrandr --output DP1 --mode 1920x1080 --rate 60

Motivation: In a multi-monitor setup, it is often necessary to configure each display individually. This command allows modifying the resolution and refresh rate of a specific output, such as DisplayPort 1, to match the desired settings.

Explanation: The --output option specifies the output to modify, in this case, DP1 (DisplayPort 1). The --mode option sets the resolution to 1920x1080, and the --rate option sets the refresh rate to 60Hz.

Example Output:

No output will be displayed for this command. However, the resolution and refresh rate of DisplayPort 1 will be updated to 1920x1080, 60Hz.

Use case 4: Set the resolution of HDMI2 to 1280x1024 and put it on the right of DP1

Code:

xrandr --output HDMI2 --mode 1280x1024 --right-of DP1

Motivation: When using multiple displays, you may want to position them in a specific arrangement. This use case shows how to set the resolution of HDMI2 and position it to the right of DP1.

Explanation: The --output option specifies the output to modify, which is HDMI2 in this case. The --mode option sets the resolution to 1280x1024. The --right-of option positions HDMI2 to the right of DP1.

Example Output:

No output will be displayed for this command. However, HDMI2 will have a resolution of 1280x1024 and will be positioned to the right of DP1.

Use case 5: Disable the VGA1 output

Code:

xrandr --output VGA1 --off

Motivation: Sometimes, it may be necessary to disable a particular display output, such as VGA1. This use case demonstrates how to turn off the VGA1 output.

Explanation: The --output option specifies the output to modify, which is VGA1 here. The --off option disables the specified output.

Example Output:

No output will be displayed for this command. However, the VGA1 output will be turned off.

Use case 6: Set the brightness for LVDS1 to 50%

Code:

xrandr --output LVDS1 --brightness 0.5

Motivation: To adjust the display brightness for a specific output, this use case sets the brightness for LVDS1 (laptop screen) to 50%.

Explanation: The --output option specifies the output to modify, which is LVDS1 (laptop screen). The --brightness option sets the brightness level, where 0.0 is completely dimmed, and 1.0 is full brightness. In this case, it sets the brightness to 0.5.

Example Output:

No output will be displayed for this command. However, the brightness of the LVDS1 output (laptop screen) will be set to 50%.

Conclusion:

The xrandr command is a powerful tool for managing displays in a Linux system. It allows users to configure screen resolutions, refresh rates, position displays, and control brightness levels. Understanding the various use cases provided in this article will help users effectively manage multi-monitor setups and optimize the display settings according to their preferences.

Related Posts

How to use the command `daemon` (with examples)

How to use the command `daemon` (with examples)

The daemon command is a useful tool for running processes as daemons in a Unix-like operating system.

Read More
How to use the command `diff` (with examples)

How to use the command `diff` (with examples)

The diff command in Linux is used to compare files and directories.

Read More
How to use the command 'nest' (with examples)

How to use the command 'nest' (with examples)

The ’nest’ command-line tool is used to initialize, develop, and maintain Nest applications.

Read More