Take command of your computer with a command line interface

Two screens showing computer code with a red box displaying the word 'PowerShell'
(Image credit: Shutterstock)

Much like the graphical user interface (GUI), the command-line interface (CLI) is something most of us working in the tech industry will be accustomed to using as a way to communicate with a computer.

Historically, this sort of communication would be done through flipping switches, before early operators moved onto using cards and Teletype machines. This was followed by electronic terminals, the rollout of which ushered in the CLI. This interface allows users to submit sophisticated commands to your machine, rather than navigating using your cursor and clicking on applications, for example. While it isn’t as visually appealing as the GUI, it’s far more capable.

Using a CLI is also much speedier than navigating the GUI. By way of example, if you need to search for all your local files changed in May 2006 you can simply type:

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

This can, of course, be done through Windows Explorer, but it takes much longer. First you’ll need to open Explorer, access the search window to bring up the Date Modified button, search for the date to bring up on a calendar, cycle your way back to May 2006, click 1 May and shift-click on 31 May, before pressing enter. Entering that one simple command seems much easier than trawling through Explorer, and most people would opt for the more laborious method.

The command above tells your machine to find all files newer than 1 May 2006 but no older than 31 May. While it may look like gibberish to the untrained eye, once you’ve devoted time to learning them, it becomes much easier to perform tham at pace.

Not only does the CLI speed up functions you can perform via the GUI, but it also gives you the capacity to do thigns that GUIs can’t. If, for example, you work for X Corp and have been writing its technical manuals for years, and you’re asked to change the name to Y Corp in all these files, this might seem like a major challenge, given 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.

How do CLIs work?

Two people looking at code on a computer monitor

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.

Photo of the UNIX interface

(Image credit: Shutterstock)

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.

Rene Millman

Rene Millman is a freelance writer and broadcaster who covers cybersecurity, AI, IoT, and the cloud. He also works as a contributing analyst at GigaOm and has previously worked as an analyst for Gartner covering the infrastructure market. He has made numerous television appearances to give his views and expertise on technology trends and companies that affect and shape our lives. You can follow Rene Millman on Twitter.