Learn the command line…. Or else!

computer text reflects earth

…. You won’t learn anything about computers.

Okay, okay. Not everyone is interested in learning the command line. I get it. (Also referred to as CLI or command line interface.) Not everyone needs to learn the command line. After all, we are becoming a mobile society where everything can be done on a smartphone or tablet. Hell, I’m typing this friggin post on my phone!

But computers don’t work in GUI, which I’ll call high level work. They work in machine code, which I’ll call low level work. Bits of zeros and ones. The closer we get to working in low level, the better we understand what the computer is really doing under the hood. Of course, it’s not efficient for people to work this way. We need to balance low level with our high level understanding. So if we consider:

  • Lowest level possible: ones and zeros, or machine language, vs,
  • Highest level possible: Special program that can take your English language instructions and can interpret it all down to machine language that does exactly what you wanted. A la Siri, but instead of searching the internet, she creates a program out of thin air that does what you want. “Siri! Download my tax forms from my bank and complete my taxes for 2017! Plz & thx.”

You’ll notice at the lowest level, you can see exactly what the computer is doing. You have full knowledge. But, it’s very hard to read it all in a timely manner and understand what it’s doing at a higher level. Example: you may see that it is adding and subtracting and multiplying lots of numbers, but it takes a while to realize it is simply calculating whether you need to take the AMT (Alternative Minimum Tax) this year.

Whereas, with the highest level, you know what the computer is theoretically doing. But, how do you know the computer is interpreting your instructions the way you want? Maybe there are some subtleties that it got wrong. How do you know?

This is why the command line is useful. You can tell the computer exactly what you want in a language that it understands and you can also go back if something goes wrong and figure out how to fix it.

What is the command line?

In Linux (I’m assuming you will be working in some variation of Linux or Unix), distributions come with various shell programs. A shell program is the most basic way to interact with the Linux kernel. Which begs the question what is a kernel? A kernel is the heart of any Linux distribution. It is what every distribution builds from. It controls the hardware and communicates with the applications and GUI (graphical User Interface). So, the shell program interacts with the kernel. There are a few different shells:

  • Bourne Again SHell (bash) is the most popular
  • Bourne shell (sh) is the original
  • C shell – get it?? C shell! XD (csh)
  • Korn shell (ksh)
  • Z shell (zsh)
  • A shell (ash)
  • Friendly Interactive shell (fish)
  • Secure shell (ssh) is used for accessing remote servers

I’ve only used bash and ssh, but I’ve heard good things about zsh. To get to the shell, you can start a terminal window. A terminal is a program that runs the shell in a nice GUI that allows you to customize your shell experience. The terminal opens with a prompt in your user folder which resides in /home/username.

You can also get to the shell by switching the user mode. You’re probably used to a GUI user mode, which in Linux is called X11. You reach X11 mode with ctrl-alt-F7 or F6, depending on your distribution. Any other ctrl-alt-function key from F1 to F6 or F8 will give you a textual interface with a shell prompt.

Even though the terminal is a GUI program, it simply shows you the shell prompt and allows you to type commands. This is the command line. Once your command runs, you are returned to your prompt to run more commands. You can also run commands in the background, in which case you’ll get a shell prompt again immediately after starting the background process.

Learning the command line is not easy. Or quick. But, the nice thing is, it’s consistent. Once you learn the rules of the command line, you can branch out more and learn more quickly. Even between operating systems.

Speaking of operating systems, there is a Windows command line if you want to learn it. It’s sometimes referred to as DOS command line. These days you can use it in Windows PowerShell, the Windows version of bash. But, it’s not as useful as learning Linux command line. Microsoft is just not amiable to people getting into its OS and making trouble so you are limited with what you can do. Even if you do find a way in, it’s probably illegal due to license agreements. My knowledge of Windows command line is limited to non-existent.

If you only have Windows, but you want to learn Linux command line, you have a couple choices. Well, three but we’ll assume you don’t want to install another operating system.

  1. Use a command line emulator app that emulates Linux commands, such as Cygwin.
  2. Use a virtual machine running Linux.

Difference between GUI and command line

The graphical user interface is a visual representation of the programs and operating system that is installed on your computer. Like all things computer, the GUI must be programmed and installed. It gives you nice looking windows and buttons and menus. All those things need to be added to the GUI program by a software developer. It is usually not practical to program in every single option or menu item that is available.

Here’s a simple example: backing up files to a server or external hard drive. You want to back up on a regular basis. But you don’t want to copy things unnecessarily. In Windows (or any GUI), you can sort a folder by date and copy only the files that have changed since the last backup. But what if your files are in more than one folder? You have to do this for every folder.

In the command line, you simply use the rsync command. Give it the options you desire along with the directory/-ies to copy and where to copy them to. It automatically compares the files to see what needs to be copied and what doesn’t.

The difficulty of CLI

To me, the hardest part about learning the command line is knowing what you can do. If you don’t know a command exists, how do you learn it?

Of course, we all know Google is our friend – or rather Duck Duck Go is our friend if you don’t want your friend to know everything about you so they can sell you stuff. My point is, you can just search how to do something. I would search something like:

Linux command line how to view devices

You may want to search using your specific distro in place of (or in addition to) Linux.

In the end, the best way to learn is to take a few tutorials, and try to do everything you would normally do with the command line. If you don’t know how to do it, ask your favorite search engine. The more you practice, the better you’ll get; and you’ll see how valuable the command line is.

Here’s a good website for beginners to get started learning the command line. Ryan does a great job explaining everything you need to know.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.