Why to use command line?

Earlier you have most probably used programs with a graphical user interface. However, it is not the only way to work, and often it is not the most efficient. Many IT professionals use the command line in some of their work. You will learn about the command line by reading the material below.

Note

Even though it is basically possible to complete all the assignments of this course with a graphical user interface, in the long run, it pays off to learn to use the command line. Working in IT without knowing the command line will be like trying to pick grains of rice with boxing gloves.

Especially programming students will want to learn to use the command line, but it will most likely be very useful even to students of other disciplines.

Graphical user interface vs. command line

The programs with a graphical user interface are usually easy and quick to learn.

However, there are limitations to the graphical user interface. The user can only perform the actions and use the objects they see. Some actions require navigating the user interface, and sometimes this is slow. We shall give you an example of a simple operation: moving some files from one location to another. One way to do it is this:

  • open the file management program
  • navigate to the file’s location
  • choose the file you want to copy
  • pick the option of copying the file, either via the menu or with shortcut keys
  • navigate to the location where the file should be placed
  • choose the paste operation, either from the menu or with shortcuts.

In the picture below, you navigate to two separate folders, and one of them is located very deep within the file system. Now that you can see the directories, you can execute the copy action.

Copy action in a graphical user interface

The same operation consists of one or two phases when done on the command line:

  • open the command line
  • write the following command on the command line: cp <command options> <source> <target>.

In Linux desktop, you can access command line by selecting e.g.

  • Applications -> System Tools -> Terminal, or
  • Applications -> System Tools -> Konsole.

In the picture below, the user is performing the same copying action as earlier, but this time they do it on the command line. You can access the directories you want by typing their location.

Copy action in command line (``cp ~/Downloads/koodi.cpp /worktmp/ohj2_staff/rounds/03/code/``)

All in all, you can perform the operation you want on the command line by writing only one command.

Why should I learn to use command line?

We asked this question from a few IT professionals. If you are already stoked to start studying the use of the command line, you can just skip these assertions and get to work in the next section.

The opinion of a developer

Anssi Heiska

– Who are you?

– Anssi Heiska. I am a designer engineer at Bitwise, and I have different tasks in various programming projects.

– What do you use the command line for in your work?

– I use the command line constantly, along with graphical user interfaces. Some options of the build-tools you need in serious development are easily accessible only via the command line. Graphical integrations usually are not developed as fast as I would need them, if at all. Basically, each big project needs some custom tools in the form of command line scripts. Also, the command line is often the only way to use computers remotely.

– What are the benefits of using the command line?

– When I use the command line, I always have a small programming language in use. It makes my work easier.

The command line makes the user interface of my computer composable, meaning I can use different parts together even if they were originally not designed for it. For example, I can pipe the result of the program ./foo forward to, say, the program ./bar, and finally I can measure the time this system takes by using the command time. I can do this without editing the programs at all. You can do all this with just one command, like this: time ./foo | ./bar. There is no such thing in any of the graphical user interfaces.

Depending on the task, the command line can be significantly more efficient than the graphical user interface. For example, it is an unrivalled tool in debugging a log file. Say, consider a task like ”you are handed dozens of log files produced by a distributed system, hundreds of megabytes in size, and you need to search them for the events of data with a certain UUID”. It is really hard to do this in the graphical user interface, but it takes just one command on the command line: grep uuid *.log | sort.

The opinion of an information security specialist

Markku Vajaranta

– What is your name?

– My name is Markku Vajaranta. I am a doctoral student in the computing sciences unit at Tampere university. Besides research and teaching, my work includes the management and development of research environments.

– What do you use the command line for in your work?

– I use the command line very often. For the needs of the research, I build the required environments over the web using the command line, save my results in text format, and finish them off with Linux tools. If I need a snippet of code, I write it on my personal computer and use the ”Deploy keys” feature of Git to push them from my private repository directly to the target. I would like to add that most of the open source programs related to information security, for example, scanners or testing tools only work from the command line.

– What are the benefits of using the command line?

– For my teaching, I sometimes have to set up environments. In those cases, it is important that you can script the command line. This means being able to produce commands programmatically. If I used the graphical user interface, I would have to repeat a couple of hundred similar mouse movements.

The opinion of an information system administrator working with Windows

– What is your name and your profession?

– Jaakko Luoto. I am a systems specialist in the IT services of the university. I am a team leader in the IT service team, and we are responsible for the centralized maintenance of Windows, Mac, and Linux workstations. We have combined systems to manage all three of them. There are about 4000 PCs in the use of the personnel and the students all over the university. Personally, I mostly work with Windows workstations.

– What do you use the command line for in your work?

– Traditionally, the most usual way to use Windows is the graphical user interface, but Windows provides the command line as well. Windows is constantly developing towards a greater use of the command line and more programming of scripts, which are written with the PowerShell programming language attached to Windows. Many of the new functions of system administration can only be used with PowerShell, and there is no possibility to use them in the graphical user interface.

In my work, I use the PowerShell and the traditional cmd-scripts for automating changes in computer settings, setting up software and updating it, amongst other things. Everyday tasks like moving files is possible with PowerShell, but I am used to using a mix of the graphical user interface, the traditional command prompt of Windows, and GNU command line tools that we know from Linux.

– What are the benefits of using the command line?

– When you need to manage several computers at once, it is useful to automate your work with the command line and scripts, which also prevents a lot of mistakes. The administration of Microsoft cloud services and Windows servers uses PowerShell as well. Basically all the job advertisements for Windows specialists ask whether you know it, and knowing it is a requirement in the technically demanding tasks.

If you get used to using the command line, you will have an easier time learning to use systems that do not include a graphical user interface.

The opinion of an information system administrator working with Linux

– What is your name and your profession?

– Timo Alatalo, systems designer in the IT services of the university. My responsibility is the development and maintenance of the Linux work stations and server environment in the university. The work includes managing the operating system itself, the maintenance tools, and developing and maintaining the services using a Linux platform. The university has just under 400 Redhat Linux computers altogether (virtual servers, desktops and laptops).

– What do you use the command line for in your work?

– You could actually ask, ”what do I not use the command line for,” because it is the default tool. I use the tools with a graphical user interface in tasks that are rare and/or complicated. Those are situations when you do not necessarily remember the commands or parameters by heart, and also the situations when there is no need to complete the same steps several times or on several computers.

The Linux command line is more like a programming or scripting language. We use the command line either for simple commands (such as ”ssh linux-ssh1.cc.tut.fi uptime”) or scripts (such as ”for i in seq 1 2 ; do ssh linux-ssh${i}.cc.tut.fi uptime ; done”). You can also write the script in a text file and then execute the script, or the program, by executing that file.

– What are the benefits of using the command line?

– Many tasks demand the use of the keyboard (i.e. writing) in any case. Using the command line speeds up the work because you do not have to switch between the keypad and the mouse. Besides, writing the command often gives you more time to think about what you are doing than clicking the mouse.

If you need to complete a task often or on several computers, using the command line and command line history or a script simplifies and speeds up your work. You also diminish the amount of errors if you execute the command on several computers from the command line history or with a script.

Using the command line is so important in my field that they ask about it and scripts in practically every job interview, and knowing how to use the command line is basically a requirement for getting the job.

Summary

All the gurus use the command line. Join them.