Linux Command Line - Using the startx 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:
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):
Enlightenment
exec enlightenment &
Afterstep
exec afterstep &
Gnome
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.
- Linux Command Line: Introduction
- Linux Command Line: ls
- Linux Command Line: cd
- Linux Command Line: mkdir
- Linux Command Line: df
- Linux Command Line: ln
- Linux Command Line: top
- Linux Command Line: mount/umount
- Linux Command Line: Cron/Crontab
- Linux Command Line: chmod
- Linux Command Line: wget
- Linux Command Line: cat
- Linux Command Line: grep
- Linux Command Line: dd
- Linux Command Line: sudo
- Linux Command Line: startx
- Linux Command Line: adduser
- Linux Command Line: at
- Linux Command Line: aterm
- Linux Command Line: nano
- Linux Command Line: hostname