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

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?

Advertisement - Article continues below

In a Linux-style command line interface, 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. 

Advertisement
Advertisement - Article continues below

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:

Advertisement - Article continues below

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 programmes 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 programme 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.

Advertisement - Article continues below

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-60s 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.

Advertisement
Advertisement - Article continues below

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.

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.

Advertisement - Article continues below

Now, things are moving ahead again. At Microsoft's virtual Build 2020 conference, the company announced that Windows Terminal, a successor to Windows Console, is hitting general availability. This includes features such the ability to run multiple tabs, GPU-accelerated text rendering for faster performance and support for Unicode and UTF-8 characters - which means it officially supports emojis. Windows Terminal can be used with all the various command-line systems Microsoft supports, including Windows, PowerShell and Windows Subsystem for Linux.

Just as thirtysomethings grew up with point and click interfaces, the next generation may know nothing other than poke-and-swipe or voice commands. 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

Staying ahead of the game in the world of data

Create successful marketing campaigns by understanding your customers better

Download now

Remote working 2020: Advantages and challenges

Discover how to overcome remote working challenges

Download now

Keep your data available with snapshot technology

Synology’s solution to your data protection problem

Download now

After the lockdown - reinventing the way your business works

Your guide to ensuring business continuity, no matter the crisis

Download now
Advertisement
Advertisement

Most Popular

How do you build a great customer experience?
Sponsored

How do you build a great customer experience?

20 Jul 2020
Labour Party donors caught up in Blackbaud data breach
data breaches

Labour Party donors caught up in Blackbaud data breach

31 Jul 2020
Why it’s time to expand beyond 16:9 monitors
Advertisement Feature

Why it’s time to expand beyond 16:9 monitors

21 Jul 2020