CODEX

Web Dev Bytes — Terrific Terminals

What are those movie hackers doing with all that green text floating around? Come get the scoop on terminals!

Evan Martinez
CodeX

--

When I was getting started in tech, by far the biggest obstacle I faced was that I didn’t have any foundational knowledge in how the internet works. These articles are my way of giving back, to any aspiring web developers or knowledge seekers looking to broaden their horizons.

Ah, the terminal. If there’s one thing I love about development, it’s getting to use a terminal. I’ll even admit that I sometimes keep a terminal window open on my desktop because it makes me feel like some sort of cool hacker. Terminals are insanely powerful, and every computer has them, but they can appear downright intimidating to the uninitiated. Today I’m going to pull back the curtain on terminals and show you what the heck is really going on.

In case you haven’t seen one, a terminal looks like this:

But you’ve probably seen them in movies where they look more like this:

If you work with any software engineers, chances are you’ve seen a window like this open on their screens at least once. In the tech world, usually, the people who need to work with software in development need to use terminals. This list includes engineers, testers, product managers, and even salespeople.

Take Control

So what’s a terminal? A terminal is a program that allows you to run computer commands using text. If that sounds vague, it’s because terminals pretty much let you do anything (barring any security policies, of course) as long as you know what to type. The reason they’re so powerful is that anything your computer can do, you can control via the terminal. I mean it! Moving files, playing music, even browsing the internet can be done with text commands!

To understand how anything can be done with text commands, you need to think a little differently about how your computer works. Most of our computer interaction is done with a keyboard and mouse because programs run in windows which require us to type and click things. For example, using an email client means we’ve got to click the app to open it, then we can scroll through the list of emails, and maybe type up a reply. But the thing to remember is that everything, and I mean EVERYTHING is controlled by code.

When you open that email app, your click is executing code that handles starting the email program. When you send your reply, an underlying command is executed that handles sending your message. Even the entire concept of a graphical interface — windows, your mouse cursor — is a program that was created so we could use a mouse to control our computers more easily. If you know what you’re doing, the terminal allows you to issue commands directly to the computer without any graphical manipulation.

Behind the Curtain

As a real-world example, consider opening a folder to view what’s inside of it. The graphical interface might show you all the files and folders as icons. Using a terminal, you could do the same thing by typing in the following command and pressing enter:

ls

Which would show you:

In reality, the graphical interfaces we use are basically running terminal commands and turning them into visual information we can process easily. If you drag a dogphoto.jpg file onto your doggos folder to move it there, the behind-the-scenes terminal command that’s running is

mv dogphoto.jpg doggos

Infinite Potential

But why should we even be using terminals? There’s no doubt that it’s much easier to browse the internet graphically using a web browser, and for many applications it’s just more efficient to manipulate visual elements. One reason is that sometimes there’s simply no graphical interface to execute the commands we need to build software. It can often be the case that we know the terminal commands we need, but nobody’s built an easy visual interface that will run them for us.

I think the more compelling reason to use terminals directly is that the commands themselves are simple and composable. Here are a few basic commands:

  • mv - Moves a file
  • cd - Navigate between folders
  • ls - Lists the files in a folder
  • cp - Copies a file
  • rm - Deletes a file
  • cat - Reads a file
  • curl - Sends a request over the internet

Each of these commands does only one, very simple thing. That makes them easy to remember. And we can also string together commands like this:

cp myfile.txt otherfolder/ && rm myfile.txt && cd otherfolder/

That example copies a file into a folder, deletes the original file, then navigates into the folder that now contains the copy. And this is what our graphical programs are doing! An email client has to run a sequence of commands like

  1. Start the program
  2. Request new emails from the internet
  3. List all the emails

But here’s the true power of having such basic terminal commands: we can run commands in any sequence we want! The commands are like building blocks, and programs are like finished buildings. A post office is great for when you need to send mail, but if I use the building blocks directly then I can build something that sends mail whenever I get new information from the internet. It’s a weird example, but I hope it makes the point that with terminal commands I can make the computer do exactly what I need it to do.

Safety Note

Of course, being able to use a terminal looks awesome. It feels almost like wizardry, being able to command the computer using just some magic words. But there’s also a dark side to this power. Graphical programs have built-in guard rails to make sure you don’t accidentally delete a file with important code in it, for example. With a terminal, you’re taking direct control of your computer. Usually, there is some security at the terminal level to make things a little safe, but it’s still a potentially dangerous world. If you’re not careful, you could cause irreparable damage to your operating system, requiring a complete reinstall. So be careful!

Now You Get It!

What a terrific tool! Using a terminal gives you direct control of your computer, allowing you to do anything you want without the constraints of graphical programs. Software developers usually need this power to develop new software, while others might have to use the terminal because there isn’t a graphical alternative (like with software that’s still being developed). I hope you’ve got a clearer understanding of what terminals are. If you’ve enjoyed the content, or would like me to cover another topic in the future, leave a comment and let me know!

--

--

Evan Martinez
CodeX
Writer for

Hey I'm Evan. I'm a software engineer who loves coding, games, and coding games! I hope to write more about philosophy and coding.