Linux Command Line - Using the startx Command

Page content

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:

startkde &

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 &


exec gnome-session

Advanced options

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.

Final Thoughts

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.

This post is part of the series: Linux Command Line

If you ever plan on doing any administration on a Linux machine, you would be well served to get to know the command line interface. In this Bright Hub series you will be introduced to various concepts surrounding one of the most powerful admin tools around.

  1. Linux Command Line: Introduction
  2. Linux Command Line: ls
  3. Linux Command Line: cd
  4. Linux Command Line: mkdir
  5. Linux Command Line: df
  6. Linux Command Line: ln
  7. Linux Command Line: top
  8. Linux Command Line: mount/umount
  9. Linux Command Line: Cron/Crontab
  10. Linux Command Line: chmod
  11. Linux Command Line: wget
  12. Linux Command Line: cat
  13. Linux Command Line: grep
  14. Linux Command Line: dd
  15. Linux Command Line: sudo
  16. Linux Command Line: startx
  17. Linux Command Line: adduser
  18. Linux Command Line: at
  19. Linux Command Line: aterm
  20. Linux Command Line: nano
  21. Linux Command Line: hostname