It is likely that you are connected to a server remotely and you need to know if the system where you are has a desktop environment installed or if you can only work from the console. Or, it is likely that you have also had to manage a local computer in which you already have a text mode session started and you do not know if there is a desktop environment installed
In any case, there are various methods to be able to know if there is a graphical environment installed from the console, with a few simple commands that will give you details about the existence or not of an environment. In addition, they are quite simple methods ...
From the CLI, you can check if there is a GUI on the system using the installation files and directories that this type of desktop environment uses. For example:
<br data-mce-bogus="1"> ls /usr/bin/*session
With that command, you will list the content of / usr / bin / * session. And if you get any results in the output, you will know that there is indeed a desktop environment installed. For example, depending on whether you are GNOME, KDE Plasma, etc., it may vary in the result, but it could be / usr / bin / gnome-session, / usr / bin / mate-session, / usr / bin / lxsession, / usr / bin / icewm-session,…
Other similar method as above it would go through listing the contents of another directory on the system and waiting for a result. In this case it would be:
ls /usr/share/xsessions/ ls /usr/share/wayland-sessions
You can try both commands, one for the graphic sessions that use the graphical server X and the second for the Wayland protocol. If you get a result, then you can deduce that there is a desktop environment installed.
Although there are many more methods, another of the existing ones that can be practical is to use a variable to query the desktop environment that is installed in a distro, returning the name of it. For example:
But be careful, use the method you use to consult, that these files are there does not mean that it is functional ...