Many new Linux users will never know about the startx command. Why? Because most distributions use a graphical log in screen. But what happens when something goes wrong with the GUI log in? You use the startx command from the console. This article will introduce you to one very useful command.
What startx does
In simplest terms the startx command is responsible for launching the X session on your computer. The X session is the underpinnings of the graphical desktop environment, without which the graphical desktop would not run. In less simple terms startx is the frontend for xinit that offers a much easier user interface.
Basic startx usage
The startx command is most often issued without arguments. It does accept arguments, but generally speaking the defaults are fine. What startx does is look for an .xinitrc file in the users ~/ directory. The .xinitrc file is a configuration file that, above all else, instructs xinit what desktop to start. Of course .xinitrc can do much more than instruct xinit what desktop to run. The .xinitrc file can also instruct xinit on variables for applications, color depth to start, background to load, etc. But the most important bit of information is the desktop. A sample single-line entry for .xinitrc that would load up the KDE desktop would look like:
and that's it.
You can start any number of window managers and desktops this way. Here are some .xinitrc entries for some of the more popular window managers or desktops (the .xinitrc entries are in italics):
exec enlightenment &
exec afterstep &
Now with the startx command you can pass some arguments to set certain options to your X session. Say, for instance, you want your X session to start up with a color depth of 16 instead of the default. To do this you would pass the argument "--16" along with the startx command like so: startx -- -depth 16. The use of the "--" indicates the end of client arguments and begins server arguments. This is actually necessary. You can also pass on to X that you are starting a multi-headed session (more than one monitor) with this command: startx -- -layout Multihead.
You may be wondering why would anyone use a text-based log in when simple, user-friendly graphical logins are available. There are a number of reasons this could be necessary. You could hose your X Windows configuration and need to have a text-based log in just to repair the setup. You may be running a server that also has X Windows loaded for administration purposes. There are a lot of reasons and you will want to be ready when the time comes that you need to be able to start an X session from the command line.