Take command of your computer with a command line interface

A CLI might not be as pretty as a GUI, but it's significantly more powerful

While most IT professionals are familiar with the command line interface (CLI), many are perfectly happy clicking around in a graphical environment, and only turn to the only turn to it when absolutely necessary - usually when something's gone wrong in the bowels of the operating system.

Like the graphical user interface (GUI) that everyone understands, a CLI is just another way of talking to a computer. Early users would operate computers by flipping switches. Then, they used punched cards before evolving to 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 faster. Let's say you need to find all files changed in May 2006. You could do that in Windows by opening Explorer, clicking in the search window to bring up the Date Modified button, and then selecting any date from it to see it appear in the search box. Then, you'd click on the date to bring up a calendar, and click your way back to May 2006. Then you'd click on May 1 and shift-click on May 31, and then press enter. Cumbersome, right?

In a Linux-style command line interface, you could type:

Advertisement - Article continues below
Advertisement - Article continues below

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 makes you a wizard at doing 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. Last week, it 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. This function can save you piles of time; alternatively, you could tell your boss you had to do it manually and then spend the next week looking at cat videos.

Advertisement - Article continues below

Command line interfaces get 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.

So how do CLIs work? It uses 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. The shell relays that 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.

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), and 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.

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 backwards-compatible with the DOS CLI.

Advertisement - Article continues below

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.

Microsoft open-sourced PowerShell in 2017, creating PowerShell Core, which is now available not just for Windows, but for Linux and even on the Mac. This was part of a broader osmosis between Microsoft and the Linux world; in 2016, it introduced the Windows Subsystem for Linux (WSL), which allowed Linux programs to work on Windows. That means Windows users can now use a Bash shell.

Advertisement - Article continues below

A technical note here: You don't access the cmd.exe or PowerShell shells directly. When you open them, they invoke the Windows Console, which is Microsoft's front-end text interface for cmd.exe. This makes Console the equivalent of the Terminal programs through which you control Bash and other shells on Linux and Mac machines.

Now, things are moving ahead again. Microsoft is preparing Windows Terminal, a successor to Windows Console, which includes new features like the ability to run multiple tabs, and the ability to render emjois (command line emojis, who would ever have imagined?)

Just as thirtysomethings grew up with point and click interfaces, the next generation may know nothing other than poke-and-swipe, and beyond that, simple voice. Each of these developments takes us further away from the power of the CLI, but if you really want mastery over your machine, its mysteries are well worth exploring further.

Featured Resources

Transform the operator experience with enhanced automation & analytics

Bring networking into the digital era

Download now

Artificially intelligent data centres

How the C-Suite is embracing continuous change to drive value

Download now

Deliver secure automated multicloud for containers with Red Hat and Juniper

Learn how to get started with the multicloud enabler from Red Hat and Juniper

Download now

Get the best out of your workforce

7 steps to unleashing their true potential with robotic process automation

Download now

Most Popular


Patch issued for critical Windows bug

11 Dec 2019
Microsoft Azure

Microsoft, not Amazon, is going to win the cloud wars

30 Nov 2019
Microsoft Windows

This exploit could give users free Windows 7 updates beyond 2020

9 Dec 2019

Buy IT to grow, not slow, your business

25 Nov 2019