Take command of your computer with a command line interface

A CLI might not look as good as a GUI, but it can pack a punch

Most IT professionals will be familiar with the command-line interface (CLI). Like the graphical user interface (GUI), a CLI is just another way of talking to a computer.

Early users would operate computers by flipping switches. before moving on to cards and Teletype machines. Electronic terminals were next, and that's where the CLI started. It lets you type sophisticated commands for your computer rather than waving a mouse around, and even though it isn't as pretty as a GUI, it's far more powerful.

A CLI is also much faster. Let's say you need to find all files changed in May 2006. You could do this in Windows using Explorer, but it's a cumbersome processor; you'd need to open Explorer, click in the search window to bring up the Date Modified button, search the date to bring up a calendar, click your way back to May 2006, click May 1 and shift-click on May 31, and then press enter. Tiresome, right?

In a Linux-style CLI, you could simply type:

find . -type f -newermt 20060501 \! -newermt 20060601

This tells the computer to find all files newer than May 1, 2006, but not older than May 31. The commands may seem like gibberish, but once you take the time to learn them, it becomes much easier to do things quickly. 

A CLI interface doesn't just speed up GUI functions - it lets you do things that GUIs can't. Let's say you work for X Corp. You've been writing its technical manuals forever, and last week, the company changed its name to Y Corp. Your manager tells you to change the name in the last five years of documents. There are hundreds of them buried in a folder structure six layers deep.

You can find those documents in the Windows GUI easily enough but changing their text would be a nightmare. On a Linux command line, you can do it in one line:

find . -type f -exec sed -i 's/X Corp/Y Corp/g' {} +

This finds all the files in the directory and then uses a replacement function, sed, to swap out the text. 

CLIs become even more powerful when you chain multiple commands together, using one command's output as the input for the next. Modern CLIs are even scriptable, so you can write small programs to perform many repetitive tasks. It's easy to see why expert system administrators prefer the CLI to a GUI. They can use it to automate tasks at an advanced level.

Two people looking at code on a computer monitor

How do CLIs work?

These tools use a shell, which is a program that interprets your commands and then sends them to the underlying operating system kernel, which runs them and produces an output that is relayed back to you. It can run on your own computer or on a remote server, accessible using a program that lets you use the shell remotely, like telnet or ssh.

How the command line interface has changed over the years

Command-line shells really began with Unix systems and their predecessors. One of the first shells was Runcom, a program developed at MIT in the mid-sixties that allowed admins to run lots of commands as batch files. Then the Thompson shell appeared in 1971, but was mostly just an interpreter, running commands as the user typed them in, with some limited scripting capabilities.

Shells evolved again with the creation of the Bourne shell (known as sh). This was introduced in 1977 as a replacement for the V6 shell and developed by Stephen Bourne at Bell Labs. This is intended to be used as a scripting language and has most of the features that are usually considered to produce structured programs.

Evolving from the Bourne shell is one of its most popular successors, Bash (Bourne-again shell). Released in 1989, the Bash free open-source shell has become the de facto standard on Linux systems, but there are many others to choose from. Bash was written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell.

While Bash has been popular on Linux, it has also featured in Apple’s OS X and MacOS operating systems up to Catalina in 2019. Bash has also been ported to Windows.

Another variant of the Bourne shell is the Korn shell (ksh) written by David Korn. This offers a middle path between the Bourne shell and the C shell (This itself was created by Bill Joy in the late 1970s while Joy was a student at the University of California at Berkeley). Korn shell had the syntax of the Bourne shell, but its job control features looked more like those found in C shell.

Microsoft also has its own rich history of CLIs. The original MS-DOS operating system was CLI-based, and early Windows versions were GUI shells running on DOS. Following ventures like Xenix (Microsoft's version of Unix) and OS/2, Windows NT became the basis for modern Windows. This introduced the CMD.exe shell, designed to be backward-compatible with the DOS CLI.

CMD.exe was not only the default command-line interpreter for Windows but also OS/2, eComStation, ArcaOS, and ReactOS. It is also known as Command Prompt, referring to the default window title on Windows. CMD.exe is the counterpart of COMMAND.COM in DOS and Windows 9x systems.

However, CMD.exe would soon prove inadequate for more sophisticated modern-day tasks, so Microsoft created PowerShell. This was a more sophisticated object-oriented CLI that enabled users to manipulate every part of the Windows system. It enables users to streamline and automate recurring tasks by producing scripts and merging multiple commands.

Unlike other shells that accept and return text, PowerShell is built on top of the .NET Common Language Runtime (CLR) and accepts and returns .NET objects. Developed by Microsoft for task automation and configuration management, the first version of PowerShell was released in November 2006 for Windows XP, Windows Server 2003, and Windows Vista. 

Building a CLI for the future

PowerShell Core, the open-source version of PowerShell released in 2017, gave users with Linux and even Mac systems access to the powerful CLI tool. This decision also formed part of a broader Microsoft shift towards embracing Linux, having first introduced the Windows Subsystem for Linux (WSL) in 2016, allowing programs to work on Windows operating systems, meaning Windows users could use a Bash shell.

Technically speaking, you don’t need to access cmd.exe or PowerShell directly, rather they invoke the Windows Console when you open them, which is Microsoft’s front-end user interface for cmd.exe. It renders Console essentially the same as Terminal, through which you can control Bash and other shells on Linux and Mac systems.

The company has since announced at its virtual Build 2020 conference that Windows Terminal, the successor to Windows Console, would be generally available. Among the features are multi-tabs, GPU-accelerated text rendering, and support for Unicode and UTF-8 characters. This means official support for emojis. Additionally, Windows Terminal can be used with various command-line systems that Microsoft also supports, including Windows PowerShell and WSL.

With the nature of the CLI evolving over time, the next generation of techies and programmers may potentially be entirely unfamiliar with the sorts of tools that have been in use for generations. This cohort may instead come to rely on voice commands or gesture-based systems. Each step represents a significant shift from the power of the CLI, although it’s well worth exploring this tool in more depth if you wish to retain ultimate control over your device.

Featured Resources

Become a digital service provider

How to transform your business from network core to edge

Download now

Optimal business results with the cloud

Evaluating the best approaches to hybrid cloud adoption

Download now

Virtualisation that enables choices, not compromises

Harness the virtualisation technology that's right for your hybrid infrastructure

Download now

Email security threat report 2020

Four key trends from spear fishing to credentials theft

Download now

Most Popular

150,000 arrest records accidentally deleted from police database
data management

150,000 arrest records accidentally deleted from police database

15 Jan 2021
How to recover deleted emails in Gmail
email delivery

How to recover deleted emails in Gmail

6 Jan 2021
What is a 502 bad gateway and how do you fix it?
web hosting

What is a 502 bad gateway and how do you fix it?

12 Jan 2021