Introduction to the Command Line

Put Yourself in Command

Commands enable you to do all sorts of powerful things. We will demonstrate this by looking at an everyday task you might be familiar with. If you use a digital camera, you probably have a folder full of images on your computer. Imagine you wish to resize the image profile.jpg so it is 300 pixels wide and then save it as a new image called profile_small.jpg.

Using an image editing software, the steps you need to go through might be as follows:

  1. Open the image editor from the Applications menu.
  2. Click File>Open.
  3. Browse to the folder where you have saved your images.
  4. Click the image file profile.jpg, and then click Open.
  5. Click Image>Scale Image to resize the selected image.
  6. Change the image width to 300 pixels, and then click Scale.
  7. Click File>Save As to save the image file.
  8. Enter profile_small.jpg as the new file name, and then click Save.


Using the command line, you can achieve the same result by typing the following:

convert -resize 300 profile.jpg profile_small.jpg

That is one step in the command line instead of eight steps using the image editor. Perhaps, you think that the time you spend on reading this book and studying the commands is not worth saving seven steps. But what if there were 30 images to be resized? Do you still want to open each image individually and repeat the process 30 times using the image editor? That would require a total of 240 steps. Would you rather just type one command instead and get the job done?

A single command can do the same thing whether you have 30 images, 300, or 3000. This is one of the most compelling reasons to start using the command line. You might start with a slow learning curve, but in the long run, it will save a lot of time. Even more important, learning the command line will open up interesting possibilities and fun ways of working. Let us look at some more reasons why learning the command line is a good idea.

Advantages of Using Commands

Many people who give the command line a try are so amazed by its possibilities that they do not even want to go back to a Graphical User Interface(GUI)! Why? Well, in brief, the command line offers the following main advantages over common graphical software:

  • Flexibility-With graphical programs, you sometimes hit a limit; you just can't do what you want or you need to find cumbersome work-arounds to program limits. With the command line, you can combine commands to yield a virtually infinite range of new and interesting functions. By combining commands creatively, you can make the command line do exactly what you want; it puts you in control of your computer.
  • Reliability-Graphical programs are often immature or even unstable. In contrast, most of the tools that the command line offers are highly reliable. One of the reasons for this reliability is their maturity; the oldest command line programs have been around since the late 1970s. This means that these command lines have been tested for over three decades. They also tend to work the same way across different operating systems, unlike most graphical tools. If you want a Swiss Army knife you can rely on, the command line is for you.
  • Speed. Fancy graphics consume a lot of your hardware's resources, often resulting in slowness or instability. The command line, on the other hand, uses the computer's resources much more sparingly, leaving memory and processing power for the tasks that you actually want to accomplish. The command line is also intrinsically faster; instead of clicking through long chains of graphical menus, you can type commands in a dozen or so keystrokes, and often apply them to multiple files or other objects. If you can type fast, this will enable you to drastically increase your productivity.
  • Experience. Using the command line is a great learning experience. When you use the command line, you communicate with your computer more directly than with the graphical programs, thus learning a lot about its inner workings. Using the command line on a regular basis is the way to becoming a GNU/Linux guru.
  • Fun. Have you ever wanted to be like those cool computer hackers who can make a GNU/Linux machine do things that you have not even dreamed of? Once you learn to use this powerful tool, you will find yourself doing funny and interesting stuff that you have never imagined.

The Value of Scripting

But wait, there's more! You can also store commands in text files. These text files are called scripts and can be used instead of typing a long series of commands each time. For example, if you store commands in a file called, you don't have to type out the commands again. Instead, you can simply type:

In addition, you can combine commands together in simple or sophisticated ways. Further, you can schedule scripts to run at a specific time or specific date or at the occurrence of a specific event on your computer.

You can also write scripts that accept additional information from you. For example, an image resizing script might ask you to what size the images should be resized before it starts the process.

Ever tried to do anything remotely like that by using a GUI? Perhaps now you can see how working with the command line interface (CLI) starts to open a whole new world to using your computer.

Is my Computer Sick?

The command line is also used to check the well-being of your computer. There are many commands you can use to check every facet of your computer's health, from the amount of space left on the hard drive to the temperature of the CPU. If your computer is acting poorly and you do not know what the matter is, a few commands will help you quickly determine whether it is a hardware or a software issue, and help you quickly rectify the problem.

Spanning the network

Another interesting feature of command line interfaces that GUIs can't match is the interaction over a network. Imagine you have a computer in another room and you wish to turn it off. How do you do that? Easy right? Get up, walk to the computer, and click on the "Shutdown" button.

Well, those who know how to connect to the computer in the next room use the command line and type halt to do the same thing.

That might seem trivial. Perhaps it's actually better for you to get up off that comfy chair and expend 5 calories walking to the next room. However, what if the computer you wanted to shut down was in another suburb? In another city? Another country?  Then, remote control of that computer might be very useful.

Shutting down a remote computer is just a start. Everything you can do on the command line you can do on the remote computer. That means you can run scripts, execute commands, edit text files, check the diagnostics, and do many other tasks. The world of the command line just got a whole lot bigger.

Even graphical programs are commands

When you click an icon or menu item to start a program, you are actually running a command. You may require, at times, to understand what commands are you are running. For instance, if you suspect a program is running invisibly in the background and slowing your computer, you can find its command and terminate the program. GUI programs often send more error messages to the command line than to GUI dialog boxes. You can often use these command line messages to diagnose problems more precisely than you can using a graphical interface.