Tip

Basic Linux commands for new Linux server administrators

If you're a Windows admin taking on some Linux servers, you'll need to learn some basic Linux commands for process management. No matter which flavor of Linux you're using, all services

    Requires Free Membership to View

are offered by your server as processes.

Finding services

Figure 1. The processes that the Linux administrator has started from the current shell, called up by the ps command.

The very first task a Linux administrator should be interested in is process management. Start by getting an overview of what your server is doing; the ps command calls up a list of all currently running processes. From a root terminal, make sure a shell is started and you have logged in as root. You can do that either by typing the user name root and the associated password at the login prompt, or by logging in with your normal user account and using the command sudo su to open a root shell.

Figure 2. All processes that are active on a Linux server, as called up by the ps aux command.

Normally the list of processes that ps discovers will be very short, as it only shows the processes that you've started from the current shell (see Figure 1). Many more processes, by default, are active on your server, and you can get a list with the ps aux command. On a typical server that isn't doing anything special, expect to see 150 processes or more.

Figure 3. The grep utility allows Linux admins to show only lines that contain a specific phrase.

Linux administrators often want to know if a specific process is running. Rather than browsing the list of active processes, you can use Linux pipes -- or program redirects -- and the versatile grep command-line utility. Using piping, you can send the output of one command to the command after the pipe: That will treat the output of the first command as input. You also can use the grep utility in a pipe to search lines that contain a specific string of characters. For example, to find out if your Web server is currently running, you would look for lines containing the text httpd, using the command ps aux | grep httpd. The ps part of the command generates a list of all processes currently running, which the grep utility filters to show only lines containing the text httpd (see Figure 3).

Starting services

If the process you need is not running, you can start it manually. On most Linux servers, the directory /etc/init.d contains a list of scripts that you can use to start services: use cd /etc/init.d to access the directory and type ls to show the list of services on your server (see Figure 4). While this procedure will work for the majority of Linux servers, the latest Linux distributions may use a different procedure.

Figure 4. A list of service scripts that Linux administrators can start manually.

Often the names of the service scripts make sense; for example, the httpd process is started by the httpd service script (see Figure 4). Once you find the name of the service script you need from the list of files in the directory /etc/init.d, you can use the service command to start it. In this example, the command would read service httpd start.

The service command can be used for other purposes as well. You can use it to restart a service, or request current status information. To find out if your httpd service -- or any other Linux process -- is currently running, you can use service httpd status. If it is running and you need to restart it, you can use service httpd restart.

Always type the exit command to close your root shell; you should never walk away from a server that has an open root shell.

Now you're capable of performing some basic Linux service administration tasks, and can move on to Linux files.

Sander van Vugt is an independent trainer and consultant based in the Netherlands. He is an expert in Linux high availability, virtualization and performance. He has authored many books on Linux topics, including Beginning the Linux Command Line, Beginning Ubuntu LTS Server Administration and Pro Ubuntu Server Administration.

This was first published in January 2014

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.