How to check if a graphical interface is present in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check for the presence of a graphical interface in Linux. We will explore key indicators and tools used to determine if an X server is running and configured.

You will begin by examining the DISPLAY environment variable, which is essential for graphical applications. Then, you will use the xdpyinfo command to gather detailed information about the X server. Finally, you will inspect the location of the X binary file to further confirm the presence of the X Window System.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicSystemCommandsGroup(["Basic System Commands"]) linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/UserandGroupManagementGroup(["User and Group Management"]) linux/BasicSystemCommandsGroup -.-> linux/echo("Text Display") linux/BasicFileOperationsGroup -.-> linux/ls("Content Listing") linux/UserandGroupManagementGroup -.-> linux/env("Environment Managing") subgraph Lab Skills linux/echo -.-> lab-558717{{"How to check if a graphical interface is present in Linux"}} linux/ls -.-> lab-558717{{"How to check if a graphical interface is present in Linux"}} linux/env -.-> lab-558717{{"How to check if a graphical interface is present in Linux"}} end

Check DISPLAY variable with echo $DISPLAY

In this step, we will explore the DISPLAY environment variable. The DISPLAY variable is crucial in Linux systems that use a graphical user interface (GUI). It tells graphical applications where to send their output (which screen) and where to get input from (which keyboard and mouse).

When you are working in a terminal within a graphical environment like the one provided by LabEx, the DISPLAY variable is usually set automatically. Let's check its value using the echo command, which we learned in the previous lab.

Open your terminal if it's not already open. You can find the Xfce Terminal icon on the left side of your desktop.

Type the following command and press Enter:

echo $DISPLAY

The $ before DISPLAY indicates that we want to see the value of the DISPLAY variable, not the literal word "DISPLAY".

You should see output similar to this:

:0.0

The value :0.0 is a common setting for the primary display on a local machine. It means:

  • :: Indicates the display is on the local machine.
  • 0: Refers to the display server number (the first display server).
  • .0: Refers to the screen number on that display server (the first screen).

Understanding the DISPLAY variable is important when you work with graphical applications, especially in remote environments or when troubleshooting display issues.

Click Continue to proceed to the next step.

Verify X server with xdpyinfo

In this step, we will use the xdpyinfo command to get detailed information about the X server display. The X server is the core component of the X Window System, which provides the graphical environment you are currently using. xdpyinfo is a utility that queries the X server and prints information about its capabilities and configuration.

Make sure your terminal is open. Type the following command and press Enter:

xdpyinfo

This command will output a lot of information about your display. Don't worry about understanding everything right now. We'll look at a few key pieces of information.

You will see output similar to this (the exact details may vary):

name of display:    :0.0
version number:    11.0
vendor string:    The X.Org Foundation
vendor release number:    <some_number>
...
screen #0:
  dimensions:    <width>x<height> pixels (<width_mm>x<height_mm> millimeters)
  resolution:    <dpi>x<dpi> dots per inch
  depths (w) =    24, 1, 4, 8, 16, 32
  ...

Look for lines like:

  • name of display: This should match the value you saw when you echoed the DISPLAY variable (:0.0).
  • version number: This tells you the version of the X protocol being used.
  • vendor string: This indicates who provided the X server software (commonly The X.Org Foundation).
  • screen #0: This section provides details about your primary screen, including its dimensions and resolution.

xdpyinfo is a powerful tool for diagnosing display issues or understanding the capabilities of the graphical environment.

Click Continue to move on.

Inspect X binary with ls /usr/bin/X

In this step, we will use the ls command to inspect the X server executable file. The ls command is used to list files and directories. We will use it to look at the file located at /usr/bin/X. This is typically the main executable for the X server.

Make sure your terminal is open. Type the following command and press Enter:

ls -l /usr/bin/X

Let's break down this command:

  • ls: The command to list directory contents.
  • -l: An option that tells ls to use a long listing format, which provides more details about the file, such as permissions, ownership, size, and modification date.
  • /usr/bin/X: The full path to the X server executable file.

You should see output similar to this:

lrwxrwxrwx 1 root root <size> <date> <time> /usr/bin/X -> /etc/alternatives/x-display-manager

This output tells us several things about the /usr/bin/X file:

  • lrwxrwxrwx: These are the file permissions and file type. The l at the beginning indicates that this is a symbolic link (a shortcut to another file).
  • 1: The number of hard links to the file.
  • root root: The owner and group of the file, which is typically the root user.
  • <size>: The size of the file (for a symbolic link, this is the length of the path it points to).
  • <date> <time>: The date and time the file was last modified.
  • /usr/bin/X -> /etc/alternatives/x-display-manager: This part shows that /usr/bin/X is a symbolic link pointing to /etc/alternatives/x-display-manager. This is a common way in Debian-based systems (like Ubuntu) to manage different versions or implementations of the X server.

This step shows you how to use ls to get information about specific files, which is a fundamental skill in Linux.

Click Continue to complete this lab.

Summary

In this lab, we learned how to check for the presence of a graphical interface in Linux. We started by using echo $DISPLAY to examine the DISPLAY environment variable, which indicates where graphical output should be directed. A typical output like :0.0 signifies a local display server and screen.

Next, we utilized the xdpyinfo command to query the X server and obtain detailed information about the graphical display's capabilities and configuration, further confirming the presence and details of the graphical environment.