Get to know Linux: shutdown, reboot, startx

Jack Wallen
Mar 13, 2010
Updated • Dec 2, 2012
Linux
|
3

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.

Startx

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:

exec startkde

Or, if you wanted to start GNOME, the line would look like:

exec gnome

You can also start just about any window manager in the same way.

Reboot

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

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

Final thoughts

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!

Advertisement

Previous Post: «
Next Post: «

Comments

  1. anon said on March 13, 2010 at 10:43 pm
    Reply

    Power down instead of Halt
    sudo shutdown now -P

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.