March 30, 2013

End users are often somewhat frightened at the thought of using the command-line interface of their operating system.  If you’re not familiar with CLIs, think “Command Prompt” for modern versions of Windows (or just the underlying DOS interface for older versions of Windows) or the Terminal for Unix-based OSs such as Mac and Linux.  I have never been frightened by the command line.  In fact, since I was young, I enjoyed using the text-based interface.  It felt more “real”, more like I was actually getting the computer to do something.  This predilection for CLIs probably eased my transition from Windows to Linux a couple years ago, since a large number of Linux utilities must be run from the command line, or have greater flexibility and power if run from the command line instead of through a graphical user interface.

One of the useful features of *nix systems like Linux is the ability to pipe the output of one utility into the input of another.  One example of this I used just minutes ago is the “more” utility, which allows you to display a large amount of text output one line at a time.  Let’s look at a practical example (in fact, the one I just used).  Many Linux distributions have fairly user-friendly graphical interfaces for listing processes running on your computer, similar to the “Task Manager” utility on Windows.  However, I still end up using the command line utilities for taking a look at what’s running at any given time.  The “top” utility is somewhat similar to the Windows task manager in that it will give you a dynamic listing of the top processes running on your system, i.e., the ones using the CPU and memory to the greatest extent.

However, top doesn’t give you as complete a picture as the ps utility.  Entering ps -ef at the command line will list all running processes on your system as well as the process ID numbers for each process.  This is especially useful if you have a program that’s malfunctioning and can’t make it quit using the usual methods: just find the process ID, type in “kill xxxx” (where xxxx is usually a 4 or 5 digit process ID number), and the process is gone!  For me this was a revelation coming Task Manager, where clicking “End Process” often gave zero results.  Of course, the problem with the output from the ps utility is its detail.  It’s very difficult to sort through lines and lines of processes to find the one you’re looking for.  One solution (though certainly not the only one) is to pipe the output to the more utility: ps -ef | more.  More then prints the output to the visual display one line at a time, waiting for you to press enter after each line.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: