If you use Linux long enough you are going to come face to face with a situation where you are in a GUI-less log in and you're either going to know what to do or you are not. If you don't know what to do, you will find yourself in a bit of a bind. You might find yourself face-to-face with a GUI-less server or have to reboot a machine remotely. With not GUI - how will you manage?
Simple. You use the commands that have been around since the early days of Linux: shutdown, reboot, and startx. In this article I will introduce you to these commands so you will have a solid understanding of how they are used. And hopefully the shutdown and reboot commands will rarely (if ever) be used.
Let's begin with the startx command. This command is rarely used now, because most all distributions boot into graphical mode. But there are occasions where you will want to have a GUI-enabled machine stop at console login. And when you do have to get to that GUI running, you need to know startx.
Generally speaking the use of startx command is simple. After you log in you issue, aptly enough, startx. This command will bring up your GUI. The starx command is actually a "front end" for the xinit system and allows a single instance of the X Windows system to start. One neat trick with startx is that you can add an .xinitrc file to your ~/ directory to tell startx which desktop environment to run. Say you want to run KDE. For this your .xinitrc file would contain the line:
Or, if you wanted to start GNOME, the line would look like:
You can also start just about any window manager in the same way.
If you have a console-only machine, and you have a need to reboot that machine, the easiest way to do this is to issue the command reboot. Now in some distributions the reboot command is limited to administrator-level users. So you might have to either su to root or use the sudo command in conjunction with reboot in order to successfully reboot your machine.
Shutdown is a bit more complicated than reboot. With shutdown you need to indicate a time when the process is to take place. This, of course, means you can time your shutdowns. But most often the shutdown command will look like:
shutdown -h now
The h option tells shutdown to halt the machine. Shutdown can actually reboot the machine as well (with the use of the r option). Using the now option informs shutdown that the action is to take place immediately. You can also tell shutdown to run the process at a given time. For time you can use either the +m (where m = minutes) or hh:mm (where hh is hour and mm is minutes). So if I wanted to shutdown the machine in an hour I could issue the command:
shutdown -h +60
Or, if I wanted to shutdown the machine at midnight, I could issue the command:
shutdown -h 12:00
Although these commands won't be used that often, it is wise to have them in your toolkit. You never know when you are going to be faced with the Linux console!
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.