Put Yourself In Command

Commands enable you to do all sorts of powerful things on your computer. We'll demonstrate this by looking at an everyday task that might be familiar to you. 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 save it as a new image called profile_small.jpg.

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

  1. Open an image editor from the Applications menu.
  2. Click the File>Open menu item.
  3. Browse to the folder with your images.
  4. Click the image file profile.jpg and then Open.
  5. Click the Image>Scale Image menu item, for resizing images.
  6. Change the image Width to 300 pixels and click Scale.
  7. Click the File>Save As menu item to save the file.
  8. Enter profile_small.jpg as the new file Name and click Save.

 photo_gimp.png

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

convert -resize 300 profile.jpg profile_small.jpg

That's 1 step in the command line instead of 8 steps using the graphical interface. Perhaps you think that the time you spend reading this book and studying the commands isn't worth saving 7 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 total 240 steps that you have to go through. Wouldn't you rather just type one command instead and get the job done?

A single command could do the same thing whether you had 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. Lets look at some more reasons why learning the command line is a good idea.

Summarizing the 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! 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, finding that you just can't do what you want or need to find cumbersome work-arounds to program limits. Working on the command line, though, 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 is their maturity: the oldest command line programs have been around since the late 1970s, which means that they have been tested for 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 eat up 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 are a fast typist, 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 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 haven't even dreamed of? Almost all of them do that using the command line. Once you have learned how to use this powerful tool, you will find yourself doing fun and interesting stuff that you hadn't even thought to be possible.

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 out a long series of commands each time. For example, if you store commands in a file called mycommand.sh, you don't have to type out the commands again, but simply type :

mycommand.sh

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

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

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

Is my computer sick?

Another use for the command line is 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 don't know what the matter is, a few commands will help you quickly determine whether it's a hardware or software issue, and help you make a quick recovery.

Spanning the network

There is one other interesting feature of command line interfaces that GUIs can't match: 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 that know how can connect to the computer in the next room via the command line and type halt.

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?  Remote control of that computer might then 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, etc. The world of the command line just got a whole lot bigger.

Even graphical programs are commands

When you click on an icon or menu item to start a program, you're running a command. You may find times when it's useful to understand what command you're 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 CLI, than they show in dialog boxes, this is useful to diagnose problems.