Command Lines: Why Do People Still Bother With Them?

Concept image of a Linux terminal filled with text on a laptop

The command line is almost 50 years old, but it is not obsolete. Text-based terminals remain the best way to accomplish many tasks, even in the era of graphical desks and touch screen gadgets.

In fact, the command line is more respected than ever with the creation by Microsoft a powerful new Windows Terminal application. Windows 10 PowerShell The environment is surprisingly powerful, but Microsoft has done everything to add support for the full Linux command line environment for Windows 10.

The command line was once the only option

At some point, if you wanted to interact with a computer, you would type. That was it. There was nothing else. This may seem restrictive and archaic, but the use of punch cards or perforated paper strips has made the typing radical and transformative. And migrating from TTY with their rolls of paper at the terminals with Cathode ray tube Cathode Screens (CRTs) was another radical change in human and computer interactions.

This step paved the way for the interactive shell to really take on its full dimension. You can now send instructions to the computer and quickly display the answers on your screen. You do not need a sofa-bed until your printout leaves your ticker.

Very good, but it was then, it is now. The computer is a completely different ball game. Outside unavoidable cases like the use of a computer on which no graphical desktop environment is installed or the use of a remote computer via SSH over a low bandwidth connection, or by controlling a headless or integrated Why use the command line on a graphical desktop?

The jargon explained

Terms such as command line, terminal window and shell are used almost interchangeably by some people. This is incorrect jargon. They are all very different. They are related, but it is not the same thing.

A terminal window is a window in a graphical desktop environment who runs an emulation of a teletype terminal.

The shell is the program that runs in the terminal window. It takes your input and, depending on what you have entered, attempts to interpret and execute the instructions themselves, then pass them on to some of the other utilities that make up the operating system or look for a script or program that matches what you've typed.

RELATED: What is the difference between Bash, Zsh and other Linux shells?

The command line is where you type. This is the prompt that the shell presents when it waits for you to enter instructions. The term "command line" is also used to refer to the actual content of what you typed. For example, if you talk to another computer user about a difficulty you encounter while running a program, they may ask, "What command line did you use?" They do not ask you which shell you use; they want to know what command you typed.

In total, these combine to form the command line interface (CLI).

Why use the command line in 2019?

The CLI may seem retrograde and confusing for those who do not know it. Surely there is no room in a modern operating system for such an old-fashioned and geeky way of using a computer? We did not give up all this decades ago when Windows, icons and mice appeared and the graphical desktop environments with graphical interfaces (GUI) became available?

Yes, the GUI has been around for decades. The first version of Microsoft Windows was published in 1985 and became the desktop PC standard with the release of Windows 3.0 in 1990.

The X Window System, used in Unix and Linux, was introduced in 1984. This has brought graphic desktop environments to Unix and its many derivatives, clones and ramifications.

But the release of Unix precedes these events by a more than a decade. And since there was no other option, everything had to be possible via the command line. All the human interactions, all the configurations, all the uses of the computer had to be able to be carried out via the humble keyboard.

So, ipso facto, the CLI can do anything. A GUI still can not do everything the CLI can do. And even for the parts it can achieve, the CLI is usually faster, more flexible, can be scripted and is scalable.

And there is a norm.

They are standardized thanks to POSIX

POSIX is a standard for Unix-like operating systems– basically, everything that is not Windows. And even Windows has the Windows Subsystem for Linux (WSL.) Open a terminal window on any POSIX-compliant operating system (or close to it), and you'll end up in a shell. Even if the shell or distribution provides its own extensions and enhancements, provided they provide the main POSIX functionality, you can use it immediately. And your scripts will run.

The command line is the lowest common denominator. Learn how to use it and, regardless of the Linux distribution and graphical desktop environment, you will be able to perform all the tasks you need. Different desktops have their own way of doing things. Different Linux distributions include various utilities and programs.

But open a terminal window and you will feel at home.

The controls are designed to work together

Each of the Linux commands is designed to do something in particular and to do it well. The underlying design philosophy is to add more features by adding another utility that can be hooked up or chained with existing ones to achieve the desired result.

It's so useful that Microsoft has done everything to add full linux command line support to Windows 10!

For example, the sort command is used by other commands to sort the text in alphabetical order. There is no need to create a sort function in each of the other Linux commands. Generally, GUI applications do not allow this type of collaborative interoperability.

Look at the following example. This command uses the ls command to list the files in the current directory. The results are routed in the sort order and sorted on the fifth column of data (which is the size of the file). The sorted list is then passed to the head command, which by default lists the first ten lines from his entrance.

ls -l | sort -nk5,5 | head

ls -l | sort -nk5,5 | head in a terminal window

We get a neat list of the smallest files in the current directory.

list of the ten smallest files in the current directory

By editing a command (using tail instead of head), you can get a list of the ten largest files in the current directory.

ls -l | sort -nk5,5 | tail

ls -l | sort -nk5,5 | queue in a terminal window

This gives us our list of the ten largest files, as expected.

list of the ten largest files in the current directory

The output of orders can be redirected and captured in files. Normal output (stdin) and error messages (stderr) can be captured separately.

RELATED: What are stdin, stdout and stderr under Linux?

The commands can include environment variables. The following command will list the contents of your home directory:

ls $ HOME

ls $ HOME in a terminal window

It works wherever you are in the tree.

list of the home directory in the terminal window

If the idea of ​​all this typing still surprises you, techniques such as tabulation completion can reduce the amount of typing you must do.

Scripts enable automation and repeatability

Humans are prone to errors.

Scripts allow you to standardize a set of statements that, to your knowledge, will be executed in the same way each time the script runs. This brings consistency to the maintenance of the system. Security checks can be built into scripts that allow the script to determine whether to continue or not. This removes the need for the user to have sufficient knowledge to make the decision himself.

Because you can automate tasks By using cron on Linux and other Unix-like systems, it is possible to simplify, or at least simplify, a long, complex and repetitive task, and then automate it for the future.

PowerShell scripts provide similar power on Windows and you can schedule their execution from the task scheduler. Why click 50 different options each time you set up a computer when you can execute a command that changes everything automatically?

The best of both worlds

To make the most of Linux (or any operating system as an experienced user), you must absolutely use the CLI and GUI.

The graphical interface is unmatched for the use of applications. Even hard-working command line advocates have to step out of the terminal window and use desktop productivity suites, development environments, and graphical manipulation programs from time to time.

The addicts at the command line do not hate the graphical interface. They only favor the benefits of using the CLI for the appropriate tasks. For the administration, the CLI wins hands down. You can use the CLI to modify a file, a directory, a selection of files and directories or global changes with the same effort. Trying to do this with the GUI often requires repetitive and repetitive actions of the keyboard and mouse as the number of objects affected increases.

The command line gives you the highest fidelity. Each option of each order is available to you. And a lot of Linux commands have a lot of options. To take just one example, consider the lsof command. Look at her manual page and then think about how you integrate that into a graphical interface.

There are too many options to present to the user in an effective graphical interface. It would be overwhelming, unattractive and awkward to use. And that's the exact opposite of what is a graphical interface.

They are horses for lessons. Do not be afraid of the CLI horse. This is often the fastest and most agile courier. Earn your spurs and you'll never regret it.

Advertisements

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.